From: phk Date: Fri, 24 Mar 2006 10:46:46 +0000 (+0000) Subject: More complete HTTP parsing and logging. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9baadb3fd8554f3b717905690690f5fb02f91d5;p=varnish More complete HTTP parsing and logging. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@69 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 249089de..d95b0adc 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -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; }; diff --git a/varnish-cache/bin/varnishd/cache_acceptor.c b/varnish-cache/bin/varnishd/cache_acceptor.c index 11f4ae2c..7df59c41 100644 --- a/varnish-cache/bin/varnishd/cache_acceptor.c +++ b/varnish-cache/bin/varnishd/cache_acceptor.c @@ -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 diff --git a/varnish-cache/bin/varnishd/cache_httpd.c b/varnish-cache/bin/varnishd/cache_httpd.c index 744c306f..576f25bb 100644 --- a/varnish-cache/bin/varnishd/cache_httpd.c +++ b/varnish-cache/bin/varnishd/cache_httpd.c @@ -14,27 +14,60 @@ 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); } diff --git a/varnish-cache/include/shmlog_tags.h b/varnish-cache/include/shmlog_tags.h index d5da0145..19c7afc5 100644 --- a/varnish-cache/include/shmlog_tags.h +++ b/varnish-cache/include/shmlog_tags.h @@ -13,3 +13,4 @@ SLTM(ClientAddr) SLTM(Request) SLTM(URL) SLTM(Protocol) +SLTM(Headers)