commit - 232eee45ce904eca5fe392ba1a4f7d5f6453f142
commit + abe1778147e9ae26eeb75ba1feb5060ee40e28ee
blob - 9f6ee305974090f96125a11031ea41ed33f50917
blob + f91b4726219ad3b6279cf6434b4eb645b13cc38c
--- fragments.tmpl
+++ fragments.tmpl
#include <event.h>
#include <limits.h>
#include <stdint.h>
+#include <stdio.h>
#include <string.h>
#include "galileo.h"
</figure>
{{ end }}
-{{ define tp_error(struct template *tp, const char *reason) }}
+{{ define tp_error(struct template *tp, int code, const char *reason) }}
+{!
+ char scode[32];
+ int r;
+
+ r = snprintf(scode, sizeof(code), "%d", code);
+ if (r < 0 || (size_t)r >= sizeof(code))
+ return 0;
+
+!}
{{ render tp_head(tp, "en", "Proxy error") }}
<main>
<h1>Proxy error</h1>
- <p>Unable to serve the page due to:</p>
- <pre>{{ reason }}</pre>
+ {{ if code != -1 }}
+ <p>Request failed with code: <code>{{ scode }}</code>.</p>
+ <p>The server says: {{ reason }}.</p>
+ {{ else }}
+ <p>Unable to serve the page due to: {{ reason }}.</p>
+ {{ end }}
</main>
{{ render tp_foot(tp) }}
{{ end }}
blob - 751d06fe1ece115eb265af04a0a4eafb8a817b2c
blob + c58fdc1a1477f7d707cd7ad6810cca22c7ebaeac
--- 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 *);
+int tp_error(struct template *, int, const char *);
/* galileo.c */
int accept_reserve(int, struct sockaddr *, socklen_t *, int,
blob - 58ab1fdeeafdaf3e8da708fd14c8920f3531da3f
blob + 537ced406bbea0c7920e338d794faf0ab2550bc7
--- proxy.c
+++ proxy.c
if ((clt->clt_pc = proxy_server_match(env, clt)) == NULL) {
if (proxy_start_reply(clt, 501, "text/html") == -1)
return;
- if (tp_error(clt->clt_tp, "unknown server") == -1)
+ if (tp_error(clt->clt_tp, -1, "unknown server") == -1)
return;
fcgi_end_request(clt, 1);
return;
gai_strerror(res->ar_gai_errno));
if (proxy_start_reply(clt, 501, "text/html") == -1)
return;
- if (tp_error(clt->clt_tp, "Can't resolve host") == -1)
+ if (tp_error(clt->clt_tp, -1, "Can't resolve host") == -1)
return;
fcgi_end_request(clt, 1);
return;
clt->clt_pc->proxy_addr, clt->clt_pc->proxy_port);
if (proxy_start_reply(clt, 501, "text/html") == -1)
return;
- if (tp_error(clt->clt_tp, "Can't connect") == -1)
+ if (tp_error(clt->clt_tp, -1, "Can't connect") == -1)
return;
fcgi_end_request(clt, 1);
}
char lang[16];
char *hdr, *mime;
size_t len;
+ int code;
if (clt->clt_headersdone) {
if (clt->clt_translate)
goto err;
}
+ code = (hdr[0] - '0') * 10 + (hdr[1] - '0');
+
switch (hdr[0]) {
case '2':
/* handled below */
default:
if (proxy_start_reply(clt, 501, "text/html") == -1)
goto err;
- if (tp_error(clt->clt_tp, &hdr[3]) == -1)
+ if (tp_error(clt->clt_tp, code, &hdr[3]) == -1)
goto err;
fcgi_end_request(clt, 1);
goto err;
if (parse_mime(clt, mime, lang, sizeof(lang)) == -1) {
if (proxy_start_reply(clt, 501, "text/html") == -1)
goto err;
- if (tp_error(clt->clt_tp, "Bad response") == -1)
+ if (tp_error(clt->clt_tp, -1, "Bad response") == -1)
goto err;
fcgi_end_request(clt, 1);
goto err;
if (!clt->clt_headersdone) {
if (proxy_start_reply(clt, 501, "text/html") == -1)
return;
- if (tp_error(clt->clt_tp, "Proxy error") == -1)
+ if (tp_error(clt->clt_tp, -1, "Proxy error") == -1)
return;
} else if (status == 0) {
if (clt->clt_translate & TR_PRE) {