]> err.no Git - varnish/commitdiff
Teach RES_Error() about the canonical response code texts from
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 23 Aug 2006 07:16:03 +0000 (07:16 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 23 Aug 2006 07:16:03 +0000 (07:16 +0000)
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

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_center.c
varnish-cache/bin/varnishd/cache_pipe.c
varnish-cache/bin/varnishd/cache_response.c
varnish-cache/bin/varnishd/cache_vrt.c
varnish-cache/include/vrt.h
varnish-cache/lib/libvcl/vcc_compile.c
varnish-cache/lib/libvcl/vcc_fixed_token.c

index 50d227cb0e813afd8f6e643bad3495e1233085bd..5b6b2ae2aa3bf8a28ade9e2d2a3af76dd1fc6cba 100644 (file)
@@ -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 */
index 984e3e502feb9d274ba40d8a67159ce44c2d6194..f5a51f6940b691e799c90771e34bd3a1c81f0b72 100644 (file)
@@ -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);
        }
index 4ca4c4219bfa86ce2b20fbe3a7402d2d57c7fb03..85cdaca47a894e307902fe957ff79d8d5eb5020f 100644 (file)
@@ -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;
index 815838307587a8ee5197683bfb906408b87cb957..137470c3b974022bcf6faa2dd09fdd57c29e372d 100644 (file)
 #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)
                "  <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"
index 12de85fad82866e41d1dd788ddd2ac45d4d46d99..14e089c093fc0e4f584204283ad17d796142d1ca 100644 (file)
 /*--------------------------------------------------------------------*/
 
 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;
 }
 
index 2d2fc9f08dc74abcf6310aa7cf2c58659859508d..1915a0df47bd875d79b6921e411cc5d5e31f48cd 100644 (file)
@@ -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 *);
index b723a49370290fa40e38ed2e8d4bb428e59da2c2..547526e7df6c4eaad8a42611547622beafc5a535 100644 (file)
@@ -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");
index 79c647aed9e397d7cabb6aa172a7efb4c8eb4835..721dad3513bfb538b9338c71f3798fceb95df707 100644 (file)
@@ -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);