From: phk Date: Wed, 23 Aug 2006 07:16:03 +0000 (+0000) Subject: Teach RES_Error() about the canonical response code texts from X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6ca81546ebd17c5205dcae6a0b7e51eecb748c4;p=varnish Teach RES_Error() about the canonical response code texts from RFC2616. Add the XID as "guru meditation" in the error HTML. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@900 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 50d227cb..5b6b2ae2 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -256,7 +256,6 @@ struct sess { unsigned handling; unsigned char wantbody; int err_code; - const char *err_msg; const char *err_expl; TAILQ_ENTRY(sess) list; @@ -408,7 +407,7 @@ void VSL(enum shmlogtag tag, unsigned id, const char *fmt, ...); #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 */ diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c index 984e3e50..f5a51f69 100644 --- a/varnish-cache/bin/varnishd/cache_center.c +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -134,9 +134,8 @@ static int 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 @@ cnt_recv(struct sess *sp) 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); } diff --git a/varnish-cache/bin/varnishd/cache_pipe.c b/varnish-cache/bin/varnishd/cache_pipe.c index 4ca4c421..85cdaca4 100644 --- a/varnish-cache/bin/varnishd/cache_pipe.c +++ b/varnish-cache/bin/varnishd/cache_pipe.c @@ -54,6 +54,10 @@ PipeSession(struct sess *sp) 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; diff --git a/varnish-cache/bin/varnishd/cache_response.c b/varnish-cache/bin/varnishd/cache_response.c index 81583830..137470c3 100644 --- a/varnish-cache/bin/varnishd/cache_response.c +++ b/varnish-cache/bin/varnishd/cache_response.c @@ -10,14 +10,72 @@ #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); @@ -56,6 +114,8 @@ RES_Error(struct sess *sp, int code, const char *msg, const char *expl) " \r\n"); vsb_printf(sb, "

Error %03d %s

\r\n", code, msg); vsb_printf(sb, "

%s

\r\n", expl); + vsb_printf(sb, "

Guru Meditation:

\r\n", expl); + vsb_printf(sb, "

XID: %u

\r\n", sp->xid); vsb_cat(sb, " Varnish\r\n" " \r\n" diff --git a/varnish-cache/bin/varnishd/cache_vrt.c b/varnish-cache/bin/varnishd/cache_vrt.c index 12de85fa..14e089c0 100644 --- a/varnish-cache/bin/varnishd/cache_vrt.c +++ b/varnish-cache/bin/varnishd/cache_vrt.c @@ -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; } diff --git a/varnish-cache/include/vrt.h b/varnish-cache/include/vrt.h index 2d2fc9f0..1915a0df 100644 --- a/varnish-cache/include/vrt.h +++ b/varnish-cache/include/vrt.h @@ -42,7 +42,7 @@ int VRT_re_test(struct vsb *, const char *); 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 *); diff --git a/varnish-cache/lib/libvcl/vcc_compile.c b/varnish-cache/lib/libvcl/vcc_compile.c index b723a493..547526e7 100644 --- a/varnish-cache/lib/libvcl/vcc_compile.c +++ b/varnish-cache/lib/libvcl/vcc_compile.c @@ -732,13 +732,11 @@ Action(struct tokenlist *tl) 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"); diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index 79c647ae..721dad35 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -510,7 +510,7 @@ vcl_output_lang_h(FILE *f) 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);