r900 - in trunk/varnish-cache: bin/varnishd include lib/libvcl

phk at projects.linpro.no phk at projects.linpro.no
Wed Aug 23 09:16:03 CEST 2006


Author: phk
Date: 2006-08-23 09:16:03 +0200 (Wed, 23 Aug 2006)
New Revision: 900

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_pipe.c
   trunk/varnish-cache/bin/varnishd/cache_response.c
   trunk/varnish-cache/bin/varnishd/cache_vrt.c
   trunk/varnish-cache/include/vrt.h
   trunk/varnish-cache/lib/libvcl/vcc_compile.c
   trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
Log:
Teach RES_Error() about the canonical response code texts from
RFC2616.

Add the XID as "guru meditation" in the error HTML.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-08-23 06:55:18 UTC (rev 899)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-08-23 07:16:03 UTC (rev 900)
@@ -256,7 +256,6 @@
 	unsigned 		handling;
 	unsigned char		wantbody;
 	int			err_code;
-	const char		*err_msg;
 	const char		*err_expl;
 
 	TAILQ_ENTRY(sess)	list;
@@ -408,7 +407,7 @@
 #endif
 
 /* cache_response.c */
-void RES_Error(struct sess *sp, int code, const char *msg, const char *expl);
+void RES_Error(struct sess *sp, int code, const char *expl);
 void RES_WriteObj(struct sess *sp);
 
 /* cache_vcl.c */

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2006-08-23 06:55:18 UTC (rev 899)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2006-08-23 07:16:03 UTC (rev 900)
@@ -134,9 +134,8 @@
 cnt_error(struct sess *sp)
 {
 
-	RES_Error(sp, sp->err_code, sp->err_msg, sp->err_expl);
+	RES_Error(sp, sp->err_code, sp->err_expl);
 	sp->err_code = 0;
-	sp->err_msg = NULL;
 	sp->err_expl = NULL;
 	sp->step = STP_DONE;
 	return (0);
@@ -593,7 +592,7 @@
 	sp->wrk->acct.req++;
 	done = http_DissectRequest(sp->http, sp->fd);
 	if (done != 0) {
-		RES_Error(sp, done, NULL, NULL);
+		RES_Error(sp, done, NULL);
 		sp->step = STP_DONE;
 		return (0);
 	}

Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pipe.c	2006-08-23 06:55:18 UTC (rev 899)
+++ trunk/varnish-cache/bin/varnishd/cache_pipe.c	2006-08-23 07:16:03 UTC (rev 900)
@@ -54,6 +54,10 @@
 	w = sp->wrk;
 
 	vc = VBE_GetFd(sp->backend, sp->xid);
+	if (vc == NULL) {
+		RES_Error(sp, 503, "Backend did not reply");
+		return;
+	}
 	assert(vc != NULL);
 	VSL(SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name);
 	vc->http->logtag = HTTP_Tx;

Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c	2006-08-23 06:55:18 UTC (rev 899)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c	2006-08-23 07:16:03 UTC (rev 900)
@@ -10,15 +10,73 @@
 #include "shmlog.h"
 #include "cache.h"
 
+/*--------------------------------------------------------------------*/
+/* List of canonical HTTP response code names from RFC2616 */
 
+static struct http_msg {
+	unsigned	nbr;
+	const char	*txt;
+} http_msg[] = {
+	{ 101, "Switching Protocols" },
+	{ 200, "OK" },
+	{ 201, "Created" },
+	{ 202, "Accepted" },
+	{ 203, "Non-Authoritative Information" },
+	{ 204, "No Content" },
+	{ 205, "Reset Content" },
+	{ 206, "Partial Content" },
+	{ 300, "Multiple Choices" },
+	{ 301, "Moved Permanently" },
+	{ 302, "Found" },
+	{ 303, "See Other" },
+	{ 304, "Not Modified" },
+	{ 305, "Use Proxy" },
+	{ 306, "(Unused)" },
+	{ 307, "Temporary Redirect" },
+	{ 400, "Bad Request" },
+	{ 401, "Unauthorized" },
+	{ 402, "Payment Required" },
+	{ 403, "Forbidden" },
+	{ 404, "Not Found" },
+	{ 405, "Method Not Allowed" },
+	{ 406, "Not Acceptable" },
+	{ 407, "Proxy Authentication Required" },
+	{ 408, "Request Timeout" },
+	{ 409, "Conflict" },
+	{ 410, "Gone" },
+	{ 411, "Length Required" },
+	{ 412, "Precondition Failed" },
+	{ 413, "Request Entity Too Large" },
+	{ 414, "Request-URI Too Long" },
+	{ 415, "Unsupported Media Type" },
+	{ 416, "Requested Range Not Satisfiable" },
+	{ 417, "Expectation Failed" },
+	{ 500, "Internal Server Error" },
+	{ 501, "Not Implemented" },
+	{ 502, "Bad Gateway" },
+	{ 503, "Service Unavailable" },
+	{ 504, "Gateway Timeout" },
+	{ 505, "HTTP Version Not Supported" },
+	{ 0, NULL }
+};
+
 /*--------------------------------------------------------------------*/
 
 void
-RES_Error(struct sess *sp, int code, const char *msg, const char *expl)
+RES_Error(struct sess *sp, int code, const char *expl)
 {
 	char buf[40];
 	struct vsb *sb;
+	struct http_msg *mp;
+	const char *msg;
 
+	msg = "Unknown error";
+	for (mp = http_msg; mp->nbr != 0 && mp->nbr <= code; mp++) 
+		if (mp->nbr == code) {
+			msg = mp->txt;
+			break;
+		}
+
 	sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
 	assert(sb != NULL);
 	assert(code >= 100 && code <= 999);
@@ -56,6 +114,8 @@
 		"  <BODY>\r\n");
 	vsb_printf(sb, "    <H1>Error %03d %s</H1>\r\n", code, msg);
 	vsb_printf(sb, "    <P>%s</P>\r\n", expl);
+	vsb_printf(sb, "    <H3>Guru Meditation:</H3>\r\n", expl);
+	vsb_printf(sb, "    <P>XID: %u</P>\r\n", sp->xid);
 	vsb_cat(sb,
 		"    <I><A href=\"http://varnish.linpro.no/\">Varnish</A></I>\r\n"
 		"  </BODY>\r\n"

Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c	2006-08-23 06:55:18 UTC (rev 899)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c	2006-08-23 07:16:03 UTC (rev 900)
@@ -18,13 +18,12 @@
 /*--------------------------------------------------------------------*/
 
 void
-VRT_error(struct sess *sp, unsigned code, const char *msg, const char *expl)
+VRT_error(struct sess *sp, unsigned code, const char *expl)
 { 
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	VSL(SLT_Debug, 0, "VCL_error(%u, %s, %s)", code, msg, expl);
+	VSL(SLT_Debug, 0, "VCL_error(%u, %s)", code, expl);
 	sp->err_code = code;
-	sp->err_msg = msg;
 	sp->err_expl = expl;
 }
 

Modified: trunk/varnish-cache/include/vrt.h
===================================================================
--- trunk/varnish-cache/include/vrt.h	2006-08-23 06:55:18 UTC (rev 899)
+++ trunk/varnish-cache/include/vrt.h	2006-08-23 07:16:03 UTC (rev 900)
@@ -42,7 +42,7 @@
 
 void VRT_count(struct sess *, unsigned);
 int VRT_rewrite(const char *, const char *);
-void VRT_error(struct sess *, unsigned, const char *, const char *);
+void VRT_error(struct sess *, unsigned, const char *);
 int VRT_switch_config(const char *);
 
 char *VRT_GetHdr(struct sess *, const char *);

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.c	2006-08-23 06:55:18 UTC (rev 899)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.c	2006-08-23 07:16:03 UTC (rev 900)
@@ -732,13 +732,11 @@
 		else
 			a = 0;
 		Fc(tl, 1, "VRT_error(sp, %u", a);
-		for (i = 0; i < 2; ++i) {
-			if (tl->t->tok == CSTR) {
-				Fc(tl, 0, ", %.*s", PF(tl->t));
-				vcc_NextToken(tl);
-			} else {
-				Fc(tl, 0, ", (const char *)0");
-			}
+		if (tl->t->tok == CSTR) {
+			Fc(tl, 0, ", %.*s", PF(tl->t));
+			vcc_NextToken(tl);
+		} else {
+			Fc(tl, 0, ", (const char *)0");
 		}
 		Fc(tl, 0, ");\n");
 		Fc(tl, 1, "VRT_done(sp, VCL_RET_ERROR);\n");

Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2006-08-23 06:55:18 UTC (rev 899)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2006-08-23 07:16:03 UTC (rev 900)
@@ -510,7 +510,7 @@
 	fputs("\n", f);
 	fputs("void VRT_count(struct sess *, unsigned);\n", f);
 	fputs("int VRT_rewrite(const char *, const char *);\n", f);
-	fputs("void VRT_error(struct sess *, unsigned, const char *, const char *);\n", f);
+	fputs("void VRT_error(struct sess *, unsigned, const char *);\n", f);
 	fputs("int VRT_switch_config(const char *);\n", f);
 	fputs("\n", f);
 	fputs("char *VRT_GetHdr(struct sess *, const char *);\n", f);




More information about the varnish-commit mailing list