commit - 2df73ca57f0f74cefb6136e53c74a1c09c03c5c7
commit + e3c1cbab1623421ba65631719de71534f41597a3
blob - 47972ac4e436e4ff4bf9a5a6c0ada9064adb0042
blob + 9f6ee305974090f96125a11031ea41ed33f50917
--- fragments.tmpl
+++ fragments.tmpl
!}
{{ define tp_head(struct template *tp, const char *lang,
- const char *stylesheet) }}
+ const char *title) }}
+{! struct client *clt = tp->tp_arg; !}
+{! struct proxy_config *pc = clt->clt_pc; !}
+{! const char *stylesheet = pc->stylesheet; !}
+{! const char *path = clt->clt_path_info; !}
<!doctype html>
<html{{ if *lang != '\0' }}lang="{{ lang }}"{{ end }}>
<head>
{{ if *stylesheet != '\0' }}
<link rel="stylesheet" href="{{ stylesheet|urlescape }}" />
{{ end }}
+ <title>
+ {{ if title }}
+ {{ title }}
+ {{ else }}
+ gemini://{{ pc->proxy_name }}{{ path }}
+ {{ end }}
+ </title>
</head>
<body>
{{ end }}
</figcaption>
</figure>
{{ end }}
+
+{{ define tp_error(struct template *tp, const char *reason) }}
+ {{ render tp_head(tp, "en", "Proxy error") }}
+ <main>
+ <h1>Proxy error</h1>
+ <p>Unable to serve the page due to:</p>
+ <pre>{{ reason }}</pre>
+ </main>
+ {{ render tp_foot(tp) }}
+{{ end }}
blob - 595f05ec0916cb194741e3f8f6d831dd3430c142
blob + bede9bcd83c52199ed920b3b4a3b8ac63d7a072a
--- galileo.h
+++ galileo.h
int tp_head(struct template *, const char *, const char *);
int tp_foot(struct template *);
int tp_figure(struct template *, const char *, const char *);
+int tp_error(struct template *, const char *);
/* galileo.c */
int accept_reserve(int, struct sockaddr *, socklen_t *, int,
blob - 3af008c7e46ff921680aae893019c2ed5ea69d83
blob + 44302b7b6add1c4ed72d4a41d01762fe09db3ca5
--- proxy.c
+++ proxy.c
char port[32];
if ((clt->clt_pc = proxy_server_match(env, clt)) == NULL) {
- if (proxy_start_reply(clt, 501, NULL) == -1)
+ if (proxy_start_reply(clt, 501, "text/html") == -1)
return;
+ if (tp_error(clt->clt_tp, "unknown server") == -1)
+ return;
fcgi_end_request(clt, 1);
return;
}
log_warnx("failed to resolve %s:%d: %s",
pc->proxy_addr, pc->proxy_port,
gai_strerror(res->ar_gai_errno));
- if (proxy_start_reply(clt, 501, "text/plain") == -1)
+ if (proxy_start_reply(clt, 501, "text/html") == -1)
return;
- if (clt_printf(clt, "Proxy error; connection failed") == -1)
+ if (tp_error(clt->clt_tp, "Can't resolve host") == -1)
return;
fcgi_end_request(clt, 1);
return;
err:
log_warn("failed to connect to %s:%d",
clt->clt_pc->proxy_addr, clt->clt_pc->proxy_port);
- if (proxy_start_reply(clt, 501, "text/plain") == -1)
+ if (proxy_start_reply(clt, 501, "text/html") == -1)
return;
- if (clt_printf(clt, "Proxy error; connection failed") == -1)
+ if (tp_error(clt->clt_tp, "Can't connect") == -1)
return;
fcgi_end_request(clt, 1);
}
proxy_read(struct bufferevent *bev, void *d)
{
struct client *clt = d;
- struct proxy_config *pc = clt->clt_pc;
struct evbuffer *src = EVBUFFER_INPUT(bev);
const char *ctype;
char lang[16];
/* handled below */
break;
default:
- if (proxy_start_reply(clt, 501, "text/plain") == -1)
- goto err;
- if (clt_printf(clt, "Request failed with code %c%c\n\n",
- hdr[0], hdr[1]) == -1)
+ if (proxy_start_reply(clt, 501, "text/html") == -1)
goto err;
- if (clt_printf(clt, "The server says: %s\n", &hdr[3]) == -1)
+ if (tp_error(clt->clt_tp, &hdr[3]) == -1)
goto err;
fcgi_end_request(clt, 1);
goto err;
mime = hdr + 2 + strspn(hdr + 2, " \t");
if (parse_mime(clt, mime, lang, sizeof(lang)) == -1) {
- if (proxy_start_reply(clt, 501, "text/plain") == -1)
+ if (proxy_start_reply(clt, 501, "text/html") == -1)
goto err;
- if (clt_printf(clt, "Failed to parse the Gemini response\n")
- == -1)
+ if (tp_error(clt->clt_tp, "Bad response") == -1)
+ goto err;
fcgi_end_request(clt, 1);
goto err;
}
clt->clt_headersdone = 1;
if (clt->clt_translate &&
- tp_head(clt->clt_tp, lang, pc->stylesheet) == -1)
+ tp_head(clt->clt_tp, lang, NULL) == -1)
goto err;
/*
err);
if (!clt->clt_headersdone) {
- if (proxy_start_reply(clt, 501, "text/plain") == -1)
+ if (proxy_start_reply(clt, 501, "text/html") == -1)
return;
- if (clt_printf(clt, "Proxy error\n") == -1)
+ if (tp_error(clt->clt_tp, "Proxy error") == -1)
return;
} else if (status == 0) {
if (clt->clt_translate & TR_PRE) {