Commit Diff


commit - 232eee45ce904eca5fe392ba1a4f7d5f6453f142
commit + abe1778147e9ae26eeb75ba1feb5060ee40e28ee
blob - 9f6ee305974090f96125a11031ea41ed33f50917
blob + f91b4726219ad3b6279cf6434b4eb645b13cc38c
--- fragments.tmpl
+++ fragments.tmpl
@@ -24,6 +24,7 @@
 #include <event.h>
 #include <limits.h>
 #include <stdint.h>
+#include <stdio.h>
 #include <string.h>
 
 #include "galileo.h"
@@ -98,12 +99,25 @@ gemini://{{ host }}{{ path }}
 </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
@@ -166,7 +166,7 @@ int	 fcgi_client_cmp(struct client *, struct client *)
 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
@@ -360,7 +360,7 @@ proxy_start_request(struct galileo *env, struct client
 	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;
@@ -402,7 +402,7 @@ proxy_resolved(struct asr_result *res, void *d)
 		    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;
@@ -518,7 +518,7 @@ err:
 	    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);
 }
@@ -605,6 +605,7 @@ proxy_read(struct bufferevent *bev, void *d)
 	char			 lang[16];
 	char			*hdr, *mime;
 	size_t			 len;
+	int			 code;
 
 	if (clt->clt_headersdone) {
 		if (clt->clt_translate)
@@ -630,6 +631,8 @@ proxy_read(struct bufferevent *bev, void *d)
 		goto err;
 	}
 
+	code = (hdr[0] - '0') * 10 + (hdr[1] - '0');
+
 	switch (hdr[0]) {
 	case '2':
 		/* handled below */
@@ -637,7 +640,7 @@ proxy_read(struct bufferevent *bev, void *d)
 	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;
@@ -647,7 +650,7 @@ proxy_read(struct bufferevent *bev, void *d)
 	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;
@@ -697,7 +700,7 @@ proxy_error(struct bufferevent *bev, short err, void *
 	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) {