]> err.no Git - varnish/commitdiff
Segregate http header fields into a separate structure, we will
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 3 Apr 2006 11:05:53 +0000 (11:05 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 3 Apr 2006 11:05:53 +0000 (11:05 +0000)
reuse them a few places by the looks of it.

Add VCA_UNKNOWNHDR (=10) fields for unknown HTTP headers.
If more headers arrive than that, they're lost (and logged as such).

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@97 d4fa192b-c00b-0410-8231-f00ffab90ce4

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

index d8f1efb63020830443cde8cbbc39a18a8f570384..db8ed424ecd8c9605d2eed2d972f50ca06198fd4 100644 (file)
@@ -152,17 +152,17 @@ VBE_Pass(struct sess *sp)
 
        sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
        assert(sb != NULL);
-       sbuf_cat(sb, sp->req);
+       sbuf_cat(sb, sp->http.req);
        sbuf_cat(sb, " ");
-       sbuf_cat(sb, sp->url);
+       sbuf_cat(sb, sp->http.url);
        sbuf_cat(sb, " ");
-       sbuf_cat(sb, sp->proto);
+       sbuf_cat(sb, sp->http.proto);
        sbuf_cat(sb, "\r\n");
 #define HTTPH(a, b, c, d, e, f, g)                             \
        do {                                                    \
-               if (c && sp->b != NULL) {                       \
+               if (c && sp->http.b != NULL) {                  \
                        sbuf_cat(sb, a ": ");                   \
-                       sbuf_cat(sb, sp->b);                    \
+                       sbuf_cat(sb, sp->http.b);               \
                        sbuf_cat(sb, "\r\n");                   \
                }                                               \
        } while (0);
index c05cea9faa578188992d9a7b8547b6d13140c10d..5c74b0205a00b9b1abb263b80a2a0b558f9515de 100644 (file)
@@ -22,30 +22,30 @@ HttpdAnalyze(struct sess *sp)
        sp->handling = HND_Unclass;
 
        /* First, isolate and possibly identify request type */
-       sp->req = sp->rcv;
+       sp->http.req = sp->rcv;
        for (p = sp->rcv; isalpha(*p); p++)
                ;
-       VSLR(SLT_Request, sp->fd, sp->req, p);
+       VSLR(SLT_Request, sp->fd, sp->http.req, p);
        *p++ = '\0';
 
        /* Next find the URI */
        while (isspace(*p))
                p++;
-       sp->url = p;
+       sp->http.url = p;
        while (!isspace(*p))
                p++;
-       VSLR(SLT_URL, sp->fd, sp->url, p);
+       VSLR(SLT_URL, sp->fd, sp->http.url, p);
        *p++ = '\0';
 
        /* Finally, look for protocol, if any */
        while (isspace(*p) && *p != '\n')
                p++;
-       sp->proto = p;
+       sp->http.proto = p;
        if (*p != '\n') {
                while (!isspace(*p))
                        p++;
        }
-       VSLR(SLT_Protocol, sp->fd, sp->proto, p);
+       VSLR(SLT_Protocol, sp->fd, sp->http.proto, p);
        *p++ = '\0';
 
        while (isspace(*p) && *p != '\n')
@@ -55,9 +55,7 @@ HttpdAnalyze(struct sess *sp)
        if (*p == '\r')
                p++;
 
-#define HTTPH(a, b, c, d, e, f, g)     sp->b = NULL;
-#include "http_headers.h"
-#undef HTTPH
+       memset(&sp->http, 0, sizeof sp->http);
 
        for (; p < sp->rcv + sp->rcv_len; p = r) {
                q = strchr(p, '\n');
@@ -72,7 +70,7 @@ HttpdAnalyze(struct sess *sp)
     if (!strncasecmp(p, a, strlen(a))) {               \
        for (p += strlen(a); p < q && isspace(*p); p++) \
                continue;                               \
-       sp->b = p;                                      \
+       sp->http.b = p;                                 \
        VSLR(SLT_##b, sp->fd, p, q);                    \
        continue;                                       \
     } 
@@ -81,7 +79,11 @@ HttpdAnalyze(struct sess *sp)
 #include "http_headers.h"
 #undef HTTPH
 #undef W
-               VSLR(SLT_H_Unknown, sp->fd, p, q);
+               if (sp->http.nuhdr < VCA_UNKNOWNHDR) {
+                       sp->http.uhdr[sp->http.nuhdr++] = p;
+                       VSLR(SLT_HD_Unknown, sp->fd, p, q);
+               } else {
+                       VSLR(SLT_HD_Lost, sp->fd, p, q);
+               }
        }
-
 }
index d15590d5aad42f8f5a6cf7cd81cb04cf1f86fa34..0da549de31f6848a74d61df44946b46c18e3a730 100644 (file)
@@ -55,19 +55,19 @@ PipeSession(struct sess *sp)
 
        sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
        assert(sb != NULL);
-       sbuf_cat(sb, sp->req);
+       sbuf_cat(sb, sp->http.req);
        sbuf_cat(sb, " ");
-       sbuf_cat(sb, sp->url);
-       if (sp->proto != NULL) {
+       sbuf_cat(sb, sp->http.url);
+       if (sp->http.proto != NULL) {
                sbuf_cat(sb, " ");
-               sbuf_cat(sb, sp->proto);
+               sbuf_cat(sb, sp->http.proto);
        }
        sbuf_cat(sb, "\r\n");
 #define HTTPH(a, b, c, d, e, f, g)                             \
        do {                                                    \
-               if (sp->b != NULL) {                            \
+               if (sp->http.b != NULL) {                       \
                        sbuf_cat(sb, a ": ");                   \
-                       sbuf_cat(sb, sp->b);                    \
+                       sbuf_cat(sb, sp->http.b);               \
                        sbuf_cat(sb, "\r\n");                   \
                }                                               \
        } while (0);
index 2522e9e4b463871678773977b2b629326cd554b6..83b779d8889f07de7ecb62b5507e117ae71487d7 100644 (file)
@@ -13,7 +13,8 @@ SLTM(ClientAddr)
 SLTM(Request)
 SLTM(URL)
 SLTM(Protocol)
-SLTM(H_Unknown)
+SLTM(HD_Unknown)
+SLTM(HD_Lost)
 #define HTTPH(a, b, c, d, e, f, g)     SLTM(b)
 #include "http_headers.h"
 #undef HTTPH
index dad14f8b8c3656931b5df9d323d30ca3aa50c6bd..a57f3a0b94915f48bf51c8fc51580bc415ea8e44 100644 (file)
@@ -22,6 +22,18 @@ struct vcl_acl {
 
 #define VCA_RXBUFSIZE          1024
 #define VCA_ADDRBUFSIZE                32
+#define VCA_UNKNOWNHDR         10
+
+struct httphdr {
+       const char              *req;
+       const char              *url;
+       const char              *proto;
+#define HTTPH(a, b, c, d, e, f, g) const char *b;
+#include <http_headers.h>
+#undef HTTPH
+       const char              *uhdr[VCA_UNKNOWNHDR];
+       unsigned                nuhdr;
+};
 
 struct sess {
        int                     fd;
@@ -34,12 +46,7 @@ struct sess {
        unsigned                rcv_len;
 
        /* HTTP request info, points into rcv */
-       const char              *req;
-       const char              *url;
-       const char              *proto;
-#define HTTPH(a, b, c, d, e, f, g) const char *b;
-#include <http_headers.h>
-#undef HTTPH
+       struct httphdr          http;
 
        enum {
                HND_Unclass,
index 8323fe718aa72ab1b09c7e0001be986e9beebd77..f21c63e4736ba6c1e466b6795207f641df265ee8 100644 (file)
@@ -403,18 +403,9 @@ vcl_output_lang_h(FILE *f)
        fputs("\n", f);
        fputs("#define VCA_RXBUFSIZE            1024\n", f);
        fputs("#define VCA_ADDRBUFSIZE          32\n", f);
+       fputs("#define VCA_UNKNOWNHDR           10\n", f);
        fputs("\n", f);
-       fputs("struct sess {\n", f);
-       fputs(" int                     fd;\n", f);
-       fputs("\n", f);
-       fputs(" /* formatted ascii client address */\n", f);
-       fputs(" char                    addr[VCA_ADDRBUFSIZE];\n", f);
-       fputs("\n", f);
-       fputs(" /* Receive buffer for HTTP header */\n", f);
-       fputs(" char                    rcv[VCA_RXBUFSIZE + 1];\n", f);
-       fputs(" unsigned                rcv_len;\n", f);
-       fputs("\n", f);
-       fputs(" /* HTTP request info, points into rcv */\n", f);
+       fputs("struct httphdr {\n", f);
        fputs(" const char              *req;\n", f);
        fputs(" const char              *url;\n", f);
        fputs(" const char              *proto;\n", f);
@@ -455,6 +446,22 @@ vcl_output_lang_h(FILE *f)
        fputs("HTTPH(\"TE\",                    H_TE,                   0, 0, 0, 0, 0)\n", f);
        fputs("HTTPH(\"User-Agent\",            H_User_Agent,           1, 0, 0, 0, 0)\n", f);
        fputs("#undef HTTPH\n", f);
+       fputs(" const char              *uhdr[VCA_UNKNOWNHDR];\n", f);
+       fputs(" unsigned                nuhdr;\n", f);
+       fputs("};\n", f);
+       fputs("\n", f);
+       fputs("struct sess {\n", f);
+       fputs(" int                     fd;\n", f);
+       fputs("\n", f);
+       fputs(" /* formatted ascii client address */\n", f);
+       fputs(" char                    addr[VCA_ADDRBUFSIZE];\n", f);
+       fputs("\n", f);
+       fputs(" /* Receive buffer for HTTP header */\n", f);
+       fputs(" char                    rcv[VCA_RXBUFSIZE + 1];\n", f);
+       fputs(" unsigned                rcv_len;\n", f);
+       fputs("\n", f);
+       fputs(" /* HTTP request info, points into rcv */\n", f);
+       fputs(" struct httphdr          http;\n", f);
        fputs("\n", f);
        fputs(" enum {\n", f);
        fputs("         HND_Unclass,\n", f);