]> err.no Git - varnish/commitdiff
More complete HTTP parsing and logging.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 24 Mar 2006 10:46:46 +0000 (10:46 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 24 Mar 2006 10:46:46 +0000 (10:46 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@69 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_acceptor.c
varnish-cache/bin/varnishd/cache_httpd.c
varnish-cache/include/shmlog_tags.h

index 249089de23eae5d81032a152aebb6e382c7356ed..d95b0adce98e919600ef55bbe518532b15c14de2 100644 (file)
@@ -4,11 +4,34 @@
 
 #define VCA_RXBUFSIZE          1024
 #define VCA_ADDRBUFSIZE                32
+
 struct sess {
        int             fd;
-       char            rcv[VCA_RXBUFSIZE + 1];
+
+       /* formatted ascii client address */
        char            addr[VCA_ADDRBUFSIZE];
+
+       /* Receive buffer for HTTP header */
+       char            rcv[VCA_RXBUFSIZE + 1];
        unsigned        rcv_len;
+
+       /* HTTP request info, points into rcv */
+       const char      *req_b;
+       const char      *req_e;
+       const char      *url_b;
+       const char      *url_e;
+       const char      *proto_b;
+       const char      *proto_e;
+       const char      *hdr_b;
+       const char      *hdr_e;
+
+       enum {
+               HND_Unclass,
+               HND_Handle,
+               HND_Pass
+       }               handling;
+
+       /* Various internal stuff */
        struct event    *rd_e;
        struct sessmem  *mem;
 };
index 11f4ae2c698c9052a4a50023356f781d4005ade6..7df59c413ebbd2589f6e472f26b0c7ae8ac95356 100644 (file)
@@ -64,9 +64,9 @@ http_read_f(int fd, short event, void *arg)
                        continue;
                break;
        }
+       sp->hdr_e = p;
        event_del(sp->rd_e);
        HttpdAnalyze(sp);
-       printf("full <%s>\n", sp->rcv);
 }
 
 static void
index 744c306f3a6269340c9c10fe5bb93afcdbeca2d3..576f25bb3e942598bf21174381ecf45948efed2f 100644 (file)
 void
 HttpdAnalyze(struct sess *sp)
 {
-       const char *p, *q, *u;
+       const char *p, *q;
 
-       p = sp->rcv;
+       sp->handling = HND_Unclass;
 
+       /* First, isolate and possibly identify request type */
+       p = sp->req_b = sp->rcv;
        if (p[0] == 'G' && p[1] == 'E' && p[2] == 'T' && p[3] == ' ') {
-               p += 4;
-               VSL(SLT_Request, sp->fd, "GET");
+               p = sp->req_e = p + 4;
+               sp->handling = HND_Handle;
        } else if (p[0] == 'H' && p[1] == 'E' && p[2] == 'A' && p[3] == 'D'
            && p[4] == ' ') {
-               p += 5;
-               VSL(SLT_Request, sp->fd, "HEAD");
+               p = sp->req_e = p + 5;
+               sp->handling = HND_Handle;
        } else {
-               for (q = p; isupper(*q); q++)
+               /*
+                * We don't bother to identify the rest, we won't handle
+                * them in any case
+                */
+               for (q = p; isalpha(*q); q++)
                        ;
-               VSLR(SLT_Request, sp->fd, p, q);
-               p = q;
+               p = sp->req_e = q;
+               sp->handling = HND_Pass;
        }
+       VSLR(SLT_Request, sp->fd, sp->req_b, sp->req_e);
+
+       /* Next find the URI */
        while (isspace(*p))
                p++;
-       u = p;
+       sp->url_b = p;
        while (!isspace(*p))
                p++;
-       VSLR(SLT_URL, sp->fd, u, p);
+       sp->url_e = p;
+       VSLR(SLT_URL, sp->fd, sp->url_b, sp->url_e);
+
+       /* Finally, look for protocol, if any */
+       while (isspace(*p) && *p != '\n')
+               p++;
+       sp->proto_b = sp->proto_e = p;
+       if (*p != '\n') {
+               while (!isspace(*p))
+                       p++;
+               sp->proto_e = p;
+       }
+       VSLR(SLT_Protocol, sp->fd, sp->proto_b, sp->proto_e);
+
+       /*
+        * And mark the start of headers.  The end of headers 
+        * is already set in acceptor where we detected the complete request.
+        */
+       while (*p != '\n')
+               p++;
+       p++;
+       while (isspace(*p) && *p != '\n')
+               p++;
+       sp->hdr_b = p;
+       VSLR(SLT_Headers, sp->fd, sp->hdr_b, sp->hdr_e);
 }
index d5da0145d89d3c912311a9dc1853841a6607cf41..19c7afc5ebfd8dec7d090ae18dc68a4505f1b23a 100644 (file)
@@ -13,3 +13,4 @@ SLTM(ClientAddr)
 SLTM(Request)
 SLTM(URL)
 SLTM(Protocol)
+SLTM(Headers)