]> err.no Git - varnish/commitdiff
Add HTTP response headers and processing.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 4 Apr 2006 08:20:24 +0000 (08:20 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 4 Apr 2006 08:20:24 +0000 (08:20 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@111 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_httpd.c
varnish-cache/bin/varnishd/cache_pass.c
varnish-cache/bin/varnishd/cache_pipe.c
varnish-cache/bin/varnishd/cache_pool.c
varnish-cache/include/http_headers.h
varnish-cache/include/shmlog_tags.h
varnish-cache/include/vcl_lang.h
varnish-cache/lib/libvcl/vcl_fixed_token.c

index d4bdf282e909edb732db5c695ad6f9a1341563d1..ce776c939bcda20cd519b01fbfe02844ba11e0a8 100644 (file)
@@ -15,7 +15,7 @@ void VBE_Pass(struct sess *sp);
 void VBE_ClosedFd(void *ptr);
 
 /* cache_httpd.c */
-void HttpdAnalyze(struct sess *sp);
+void HttpdAnalyze(struct sess *sp, int rr);
 void HttpdGetHead(struct sess *sp, struct event_base *eb, sesscb_f *func);
 
 /* cache_main.c */
index d8852093670b61f970f7232db9f9021a00ea3778..5b4bbd7b0cbedb9ff14325fb1e14a77674b5555f 100644 (file)
@@ -21,7 +21,7 @@
 /*--------------------------------------------------------------------*/
 
 void
-HttpdAnalyze(struct sess *sp)
+HttpdAnalyze(struct sess *sp, int rr)
 {
        char *p, *q, *r;
 
@@ -29,37 +29,68 @@ HttpdAnalyze(struct sess *sp)
 
        memset(&sp->http, 0, sizeof sp->http);
 
-       /* First, isolate and possibly identify request type */
-       sp->http.req = sp->rcv;
-       for (p = sp->rcv; isalpha(*p); p++)
-               ;
-       VSLR(SLT_Request, sp->fd, sp->http.req, p);
-       *p++ = '\0';
+       if (rr == 1) {
+               /* First, isolate and possibly identify request type */
+               sp->http.req = sp->rcv;
+               for (p = sp->rcv; isalpha(*p); p++)
+                       ;
+               VSLR(SLT_Request, sp->fd, sp->http.req, p);
+               *p++ = '\0';
 
-       /* Next find the URI */
-       while (isspace(*p))
-               p++;
-       sp->http.url = p;
-       while (!isspace(*p))
-               p++;
-       VSLR(SLT_URL, sp->fd, sp->http.url, p);
-       *p++ = '\0';
+               /* Next find the URI */
+               while (isspace(*p))
+                       p++;
+               sp->http.url = p;
+               while (!isspace(*p))
+                       p++;
+               VSLR(SLT_URL, sp->fd, sp->http.url, p);
+               *p++ = '\0';
 
-       /* Finally, look for protocol, if any */
-       while (isspace(*p) && *p != '\n')
+               /* Finally, look for protocol, if any */
+               while (isspace(*p) && *p != '\n')
+                       p++;
+               sp->http.proto = p;
+               if (*p != '\n') {
+                       while (!isspace(*p))
+                               p++;
+               }
+               VSLR(SLT_Protocol, sp->fd, sp->http.proto, p);
+               *p++ = '\0';
+
+               while (isspace(*p) && *p != '\n')
+                       p++;
                p++;
-       sp->http.proto = p;
-       if (*p != '\n') {
+       } else {
+               /* First, protocol */
+               sp->http.proto = sp->rcv;
+               p = sp->rcv;
                while (!isspace(*p))
                        p++;
-       }
-       VSLR(SLT_Protocol, sp->fd, sp->http.proto, p);
-       *p++ = '\0';
+               *p++ = '\0';
+               VSLR(SLT_Protocol, sp->fd, sp->http.proto, p);
 
-       while (isspace(*p) && *p != '\n')
+               /* Next find the status */
+               while (isspace(*p))
+                       p++;
+               sp->http.status = p;
+               while (!isspace(*p))
+                       p++;
+               VSLR(SLT_Status, sp->fd, sp->http.status, p);
+               *p++ = '\0';
+
+               /* Next find the response */
+               while (isspace(*p))
+                       p++;
+               sp->http.response = p;
+               while (*p != '\n')
+                       p++;
+               for (q = p; q > sp->http.response && isspace(q[-1]); q--)
+                       continue;
+               *q = '\0';
+               VSLR(SLT_Response, sp->fd, sp->http.response, q);
                p++;
+       }
 
-       p++;
        if (*p == '\r')
                p++;
 
@@ -81,7 +112,10 @@ HttpdAnalyze(struct sess *sp)
        continue;                                       \
     } 
 
-#define HTTPH(a, b, c, d, e, f, g)     W(a ":", b, p, q, sp)
+#define HTTPH(a, b, c, d, e, f, g)                     \
+       if (c & rr) {                                   \
+               W(a ":", b, p, q, sp);                  \
+       }
 #include "http_headers.h"
 #undef HTTPH
 #undef W
index 183482edc8f5bd7722479ced435101f19f0a9e2e..0aa4c510d58aa9f18abad99e9753824b346ac224 100644 (file)
@@ -25,7 +25,7 @@ PassReturn(struct sess *sp)
 {
 
        HERE();
-       HttpdAnalyze(sp);
+       HttpdAnalyze(sp, 2);
 }
 
 /*--------------------------------------------------------------------*/
@@ -52,7 +52,7 @@ PassSession(struct sess *sp)
        sbuf_cat(sb, "\r\n");
 #define HTTPH(a, b, c, d, e, f, g)                             \
        do {                                                    \
-               if (c && sp->http.b != NULL) {                  \
+               if (d && sp->http.b != NULL) {                  \
                        sbuf_cat(sb, a ": ");                   \
                        sbuf_cat(sb, sp->http.b);               \
                        sbuf_cat(sb, "\r\n");                   \
@@ -62,7 +62,6 @@ PassSession(struct sess *sp)
 #undef HTTPH
        sbuf_cat(sb, "\r\n");
        sbuf_finish(sb);
-       printf("REQ: <%s>\n", sbuf_data(sb));
        i = write(fd, sbuf_data(sb), sbuf_len(sb));
        assert(i == sbuf_len(sb));
 
index 0da549de31f6848a74d61df44946b46c18e3a730..80eae135c9ab25416615e6c4ece1b30d43095c21 100644 (file)
@@ -75,7 +75,6 @@ PipeSession(struct sess *sp)
 #undef HTTPH
        sbuf_cat(sb, "\r\n");
        sbuf_finish(sb);
-       printf("REQ: <%s>\n", sbuf_data(sb));
        i = write(fd, sbuf_data(sb), sbuf_len(sb));
        assert(i == sbuf_len(sb));
 
index 4ce3517256405b2b3263983df75bb4bbf3a63d85..a1c30203ddb1c7b9602ee3815bf4b74687f6a51a 100644 (file)
@@ -31,7 +31,7 @@ CacheWorker(void *priv __unused)
                sp->vcl = GetVCL();
                AZ(pthread_mutex_unlock(&sessmtx));
 
-               HttpdAnalyze(sp);
+               HttpdAnalyze(sp, 1);
 
                sp->backend = sp->vcl->default_backend;
                /* Call the VCL program */
index 4092208da9f09260bd48d8b5fa7be535ab49c852..e04e9b6a1739089a7e9463b442c5e5b846b6c59e 100644 (file)
@@ -3,8 +3,8 @@
  *
  * a   Http header name
  * b   session field name
- * c   PassThrough handling (0=remove, 1=pass)
- * d   unused
+ * c   Request(1)/Response(2) bitfield
+ * d   Pass header
  * e   unused
  * f   unused
  * g   unused
  *    a                         b                       c  d  e  f  g 
  *--------------------------------------------------------------------
  */
-HTTPH("Accept-Charset",                H_Accept_Charset,       1, 0, 0, 0, 0)
-HTTPH("Accept-Encoding",       H_Accept_Encoding,      1, 0, 0, 0, 0)
-HTTPH("Accept-Language",       H_Accept_Language,      1, 0, 0, 0, 0)
-HTTPH("Accept",                        H_Accept,               1, 0, 0, 0, 0)
-HTTPH("Authorization",         H_Authorization,        1, 0, 0, 0, 0)
-HTTPH("Connection",            H_Connection,           0, 0, 0, 0, 0)
-HTTPH("Expect",                        H_Expect,               1, 0, 0, 0, 0)
-HTTPH("From",                  H_From,                 1, 0, 0, 0, 0)
-HTTPH("Host",                  H_Host,                 1, 0, 0, 0, 0)
-HTTPH("If-Match",              H_If_Match,             1, 0, 0, 0, 0)
-HTTPH("If-Modified-Since",     H_If_Modified_Since,    1, 0, 0, 0, 0)
-HTTPH("If-None-Match",         H_If_None_Match,        1, 0, 0, 0, 0)
-HTTPH("If-Range",              H_If_Range,             1, 0, 0, 0, 0)
-HTTPH("If-Unmodified-Since",   H_If_Unmodifed_Since,   1, 0, 0, 0, 0)
-HTTPH("Keep-Alive",            H_Keep_Alive,           0, 0, 0, 0, 0)
-HTTPH("Max-Forwards",          H_Max_Forwards,         1, 0, 0, 0, 0)
-HTTPH("Proxy-Authorization",   H_Proxy_Authorization,  1, 0, 0, 0, 0)
-HTTPH("Range",                 H_Range,                1, 0, 0, 0, 0)
-HTTPH("Referer",               H_Referer,              1, 0, 0, 0, 0)
-HTTPH("TE",                    H_TE,                   1, 0, 0, 0, 0)
-HTTPH("User-Agent",            H_User_Agent,           1, 0, 0, 0, 0)
+HTTPH("Connection",            H_Connection,           3, 0, 0, 0, 0)
+HTTPH("Keep-Alive",            H_Keep_Alive,           3, 0, 0, 0, 0)
+
+HTTPH("Accept-Charset",                H_Accept_Charset,       1, 1, 0, 0, 0)
+HTTPH("Accept-Encoding",       H_Accept_Encoding,      1, 1, 0, 0, 0)
+HTTPH("Accept-Language",       H_Accept_Language,      1, 1, 0, 0, 0)
+HTTPH("Accept",                        H_Accept,               1, 1, 0, 0, 0)
+HTTPH("Authorization",         H_Authorization,        1, 1, 0, 0, 0)
+HTTPH("Expect",                        H_Expect,               1, 1, 0, 0, 0)
+HTTPH("From",                  H_From,                 1, 1, 0, 0, 0)
+HTTPH("Host",                  H_Host,                 1, 1, 0, 0, 0)
+HTTPH("If-Match",              H_If_Match,             1, 1, 0, 0, 0)
+HTTPH("If-Modified-Since",     H_If_Modified_Since,    1, 1, 0, 0, 0)
+HTTPH("If-None-Match",         H_If_None_Match,        1, 1, 0, 0, 0)
+HTTPH("If-Range",              H_If_Range,             1, 1, 0, 0, 0)
+HTTPH("If-Unmodified-Since",   H_If_Unmodifed_Since,   1, 1, 0, 0, 0)
+HTTPH("Max-Forwards",          H_Max_Forwards,         1, 1, 0, 0, 0)
+HTTPH("Proxy-Authorization",   H_Proxy_Authorization,  1, 1, 0, 0, 0)
+HTTPH("Range",                 H_Range,                1, 1, 0, 0, 0)
+HTTPH("Referer",               H_Referer,              1, 1, 0, 0, 0)
+HTTPH("TE",                    H_TE,                   1, 1, 0, 0, 0)
+HTTPH("User-Agent",            H_User_Agent,           1, 1, 0, 0, 0)
+
+HTTPH("Server",                        H_Server,               2, 0, 0, 0, 0)
+HTTPH("Content-Type",          H_Content_Type,         2, 0, 0, 0, 0)
+HTTPH("Date",                  H_Date,                 2, 0, 0, 0, 0)
+HTTPH("Last-Modified",         H_Last_Modified,        2, 0, 0, 0, 0)
+HTTPH("Accept-Ranges",         H_Accept_Ranges,        2, 0, 0, 0, 0)
+HTTPH("Content-Length",                H_Content_Length,       2, 0, 0, 0, 0)
+HTTPH("Cache-Control",         H_Cache_Control,        2, 0, 0, 0, 0)
+HTTPH("Vary",                  H_Vary,                 2, 0, 0, 0, 0)
+HTTPH("Expires",               H_Expires,              2, 0, 0, 0, 0)
index 727b2b2da847fd7335820461e31477316f0c6d3a..89785c0610df2254b6f041aeb5d79dfba2f61846 100644 (file)
@@ -12,6 +12,8 @@ SLTM(SessionOpen)
 SLTM(SessionClose)
 SLTM(ClientAddr)
 SLTM(Request)
+SLTM(Response)
+SLTM(Status)
 SLTM(URL)
 SLTM(Protocol)
 SLTM(HD_Unknown)
index 1f6f29dd0f46c0ced9a368757545e8d13f66db29..ee80734ff34b7de81e8f1eb66e199be8cd0135a1 100644 (file)
@@ -31,6 +31,8 @@ struct httphdr {
        const char              *req;
        const char              *url;
        const char              *proto;
+       const char              *status;
+       const char              *response;
 #define HTTPH(a, b, c, d, e, f, g) const char *b;
 #include <http_headers.h>
 #undef HTTPH
index fc0b8f75adfc740600787767c0f341809c22d84e..7a991d0451055e85053b26d3edcc386aa750ab8e 100644 (file)
@@ -412,14 +412,16 @@ vcl_output_lang_h(FILE *f)
        fputs(" const char              *req;\n", f);
        fputs(" const char              *url;\n", f);
        fputs(" const char              *proto;\n", f);
+       fputs(" const char              *status;\n", f);
+       fputs(" const char              *response;\n", f);
        fputs("#define HTTPH(a, b, c, d, e, f, g) const char *b;\n", f);
        fputs("/*\n", f);
        fputs(" * $Id$\n", f);
        fputs(" *\n", f);
        fputs(" * a     Http header name\n", f);
        fputs(" * b     session field name\n", f);
-       fputs(" * c     PassThrough handling (0=remove, 1=pass)\n", f);
-       fputs(" * d     unused\n", f);
+       fputs(" * c     Request(1)/Response(2) bitfield\n", f);
+       fputs(" * d     Pass header\n", f);
        fputs(" * e     unused\n", f);
        fputs(" * f     unused\n", f);
        fputs(" * g     unused\n", f);
@@ -427,27 +429,38 @@ vcl_output_lang_h(FILE *f)
        fputs(" *    a                         b                       c  d  e  f  g \n", f);
        fputs(" *--------------------------------------------------------------------\n", f);
        fputs(" */\n", f);
-       fputs("HTTPH(\"Accept-Charset\",                H_Accept_Charset,       1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"Accept-Encoding\",       H_Accept_Encoding,      1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"Accept-Language\",       H_Accept_Language,      1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"Accept\",                        H_Accept,               1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"Authorization\",         H_Authorization,        1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"Connection\",            H_Connection,           0, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"Expect\",                        H_Expect,               1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"From\",                  H_From,                 1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"Host\",                  H_Host,                 1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"If-Match\",              H_If_Match,             1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"If-Modified-Since\",     H_If_Modified_Since,    1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"If-None-Match\",         H_If_None_Match,        1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"If-Range\",              H_If_Range,             1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"If-Unmodified-Since\",   H_If_Unmodifed_Since,   1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"Keep-Alive\",            H_Keep_Alive,           0, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"Max-Forwards\",          H_Max_Forwards,         1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"Proxy-Authorization\",   H_Proxy_Authorization,  1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"Range\",                 H_Range,                1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"Referer\",               H_Referer,              1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"TE\",                    H_TE,                   1, 0, 0, 0, 0)\n", f);
-       fputs("HTTPH(\"User-Agent\",            H_User_Agent,           1, 0, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Connection\",            H_Connection,           3, 0, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Keep-Alive\",            H_Keep_Alive,           3, 0, 0, 0, 0)\n", f);
+       fputs("\n", f);
+       fputs("HTTPH(\"Accept-Charset\",                H_Accept_Charset,       1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Accept-Encoding\",       H_Accept_Encoding,      1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Accept-Language\",       H_Accept_Language,      1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Accept\",                        H_Accept,               1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Authorization\",         H_Authorization,        1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Expect\",                        H_Expect,               1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"From\",                  H_From,                 1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Host\",                  H_Host,                 1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"If-Match\",              H_If_Match,             1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"If-Modified-Since\",     H_If_Modified_Since,    1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"If-None-Match\",         H_If_None_Match,        1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"If-Range\",              H_If_Range,             1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"If-Unmodified-Since\",   H_If_Unmodifed_Since,   1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Max-Forwards\",          H_Max_Forwards,         1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Proxy-Authorization\",   H_Proxy_Authorization,  1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Range\",                 H_Range,                1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Referer\",               H_Referer,              1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"TE\",                    H_TE,                   1, 1, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"User-Agent\",            H_User_Agent,           1, 1, 0, 0, 0)\n", f);
+       fputs("\n", f);
+       fputs("HTTPH(\"Server\",                        H_Server,               2, 0, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Content-Type\",          H_Content_Type,         2, 0, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Date\",                  H_Date,                 2, 0, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Last-Modified\",         H_Last_Modified,        2, 0, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Accept-Ranges\",         H_Accept_Ranges,        2, 0, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Content-Length\",                H_Content_Length,       2, 0, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Cache-Control\",         H_Cache_Control,        2, 0, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Vary\",                  H_Vary,                 2, 0, 0, 0, 0)\n", f);
+       fputs("HTTPH(\"Expires\",               H_Expires,              2, 0, 0, 0, 0)\n", f);
        fputs("#undef HTTPH\n", f);
        fputs(" const char              *uhdr[VCA_UNKNOWNHDR];\n", f);
        fputs(" unsigned                nuhdr;\n", f);