From 9642c57cb3e6c1eab34b8b09c923940fc0d2ddf7 Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 11 Jul 2006 07:30:53 +0000 Subject: [PATCH] Split http_Dissect() into http_DissectRequest() and http_DissectResponse() git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@420 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 3 +- varnish-cache/bin/varnishd/cache_fetch.c | 2 +- varnish-cache/bin/varnishd/cache_http.c | 192 +++++++++++++---------- varnish-cache/bin/varnishd/cache_pass.c | 2 +- varnish-cache/bin/varnishd/cache_pool.c | 2 +- varnish-cache/include/stat_field.h | 2 + 6 files changed, 116 insertions(+), 87 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index c7ffc8b5..cd3b5ac6 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -230,7 +230,8 @@ int http_HdrIs(struct http *hp, const char *hdr, const char *val); int http_GetTail(struct http *hp, unsigned len, char **b, char **e); int http_GetURL(struct http *hp, char **b); void http_RecvHead(struct http *hp, int fd, struct event_base *eb, http_callback_f *func, void *arg); -int http_Dissect(struct http *sp, int fd, int rr); +int http_DissectRequest(struct http *sp, int fd); +int http_DissectResponse(struct http *sp, int fd); enum http_build { Build_Pipe, Build_Pass, diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index e3364d66..997ac1e2 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -261,7 +261,7 @@ FetchSession(struct worker *w, struct sess *sp) http_RecvHead(hp, vc->fd, w->eb, NULL, NULL); event_base_loop(w->eb, 0); time(&sp->t_resp); - assert(http_Dissect(hp, vc->fd, 2) == 0); + assert(http_DissectResponse(hp, vc->fd) == 0); body = RFC2616_cache_policy(sp, hp); diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index a3b326d3..bd29e859 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -157,90 +157,10 @@ http_GetStatus(struct http *hp) /*--------------------------------------------------------------------*/ -int -http_Dissect(struct http *hp, int fd, int rr) +static int +http_dissect_hdrs(struct http *hp, int fd, char *p) { - char *p, *q, *r; - - assert(hp->t != NULL); - assert(hp->s < hp->t); - assert(hp->t <= hp->v); - for (p = hp->s ; isspace(*p); p++) - continue; - if (rr == 1) { - /* First, the request type (GET/HEAD etc) */ - hp->req = p; - for (; isalpha(*p); p++) - ; - VSLR(SLT_Request, fd, hp->req, p); - *p++ = '\0'; - - /* Next find the URI */ - while (isspace(*p) && *p != '\n') - p++; - if (*p == '\n') { - VSLR(SLT_Debug, fd, hp->s, hp->v); - return (400); - } - hp->url = p; - while (!isspace(*p)) - p++; - VSLR(SLT_URL, fd, hp->url, p); - if (*p == '\n') { - VSLR(SLT_Debug, fd, hp->s, hp->v); - return (400); - } - *p++ = '\0'; - - /* Finally, look for protocol */ - while (isspace(*p) && *p != '\n') - p++; - if (*p == '\n') { - VSLR(SLT_Debug, fd, hp->s, hp->v); - return (400); - } - hp->proto = p; - while (!isspace(*p)) - p++; - VSLR(SLT_Protocol, fd, hp->proto, p); - if (*p != '\n') - *p++ = '\0'; - while (isspace(*p) && *p != '\n') - p++; - if (*p != '\n') { - VSLR(SLT_Debug, fd, hp->s, hp->v); - return (400); - } - *p++ = '\0'; - } else { - /* First, protocol */ - hp->proto = p; - while (!isspace(*p)) - p++; - VSLR(SLT_Protocol, fd, hp->proto, p); - *p++ = '\0'; - - /* Next find the status */ - while (isspace(*p)) - p++; - hp->status = p; - while (!isspace(*p)) - p++; - VSLR(SLT_Status, fd, hp->status, p); - *p++ = '\0'; - - /* Next find the response */ - while (isspace(*p)) - p++; - hp->response = p; - while (*p != '\n') - p++; - for (q = p; q > hp->response && isspace(q[-1]); q--) - continue; - *q = '\0'; - VSLR(SLT_Response, fd, hp->response, q); - p++; - } + char *q, *r; if (*p == '\r') p++; @@ -262,6 +182,7 @@ http_Dissect(struct http *hp, int fd, int rr) hp->hdr[hp->nhdr++] = p; VSLR(SLT_Header, fd, p, q); } else { + VSL_stats->losthdr++; VSLR(SLT_LostHeader, fd, p, q); } } @@ -274,6 +195,111 @@ http_Dissect(struct http *hp, int fd, int rr) /*--------------------------------------------------------------------*/ +int +http_DissectRequest(struct http *hp, int fd) +{ + char *p; + + assert(hp->t != NULL); + assert(hp->s < hp->t); + assert(hp->t <= hp->v); + for (p = hp->s ; isspace(*p); p++) + continue; + + /* First, the request type (GET/HEAD etc) */ + hp->req = p; + for (; isalpha(*p); p++) + ; + VSLR(SLT_Request, fd, hp->req, p); + *p++ = '\0'; + + /* Next find the URI */ + while (isspace(*p) && *p != '\n') + p++; + if (*p == '\n') { + VSLR(SLT_Debug, fd, hp->s, hp->v); + return (400); + } + hp->url = p; + while (!isspace(*p)) + p++; + VSLR(SLT_URL, fd, hp->url, p); + if (*p == '\n') { + VSLR(SLT_Debug, fd, hp->s, hp->v); + return (400); + } + *p++ = '\0'; + + /* Finally, look for protocol */ + while (isspace(*p) && *p != '\n') + p++; + if (*p == '\n') { + VSLR(SLT_Debug, fd, hp->s, hp->v); + return (400); + } + hp->proto = p; + while (!isspace(*p)) + p++; + VSLR(SLT_Protocol, fd, hp->proto, p); + if (*p != '\n') + *p++ = '\0'; + while (isspace(*p) && *p != '\n') + p++; + if (*p != '\n') { + VSLR(SLT_Debug, fd, hp->s, hp->v); + return (400); + } + *p++ = '\0'; + + return (http_dissect_hdrs(hp, fd, p)); +} + +/*--------------------------------------------------------------------*/ + +int +http_DissectResponse(struct http *hp, int fd) +{ + char *p, *q; + + assert(hp->t != NULL); + assert(hp->s < hp->t); + assert(hp->t <= hp->v); + for (p = hp->s ; isspace(*p); p++) + continue; + + /* First, protocol */ + hp->proto = p; + while (!isspace(*p)) + p++; + VSLR(SLT_Protocol, fd, hp->proto, p); + *p++ = '\0'; + + /* Next find the status */ + while (isspace(*p)) + p++; + hp->status = p; + while (!isspace(*p)) + p++; + VSLR(SLT_Status, fd, hp->status, p); + *p++ = '\0'; + + /* Next find the response */ + while (isspace(*p)) + p++; + hp->response = p; + while (*p != '\n') + p++; + for (q = p; q > hp->response && isspace(q[-1]); q--) + continue; + *q = '\0'; + VSLR(SLT_Response, fd, hp->response, q); + p++; + + return (http_dissect_hdrs(hp, fd, p)); +} + +/*--------------------------------------------------------------------*/ + static int http_header_complete(struct http *hp) { diff --git a/varnish-cache/bin/varnishd/cache_pass.c b/varnish-cache/bin/varnishd/cache_pass.c index 5872a16e..0b0e19c2 100644 --- a/varnish-cache/bin/varnishd/cache_pass.c +++ b/varnish-cache/bin/varnishd/cache_pass.c @@ -170,7 +170,7 @@ PassSession(struct worker *w, struct sess *sp) hp = vc->http; http_RecvHead(hp, vc->fd, w->eb, NULL, NULL); event_base_loop(w->eb, 0); - http_Dissect(hp, vc->fd, 2); + http_DissectResponse(hp, vc->fd); http_BuildSbuf(sp->fd, Build_Reply, w->sb, hp); vca_write(sp, sbuf_data(w->sb), sbuf_len(w->sb)); diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index 4971db65..d4663777 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -68,7 +68,7 @@ wrk_WorkSession(struct worker *w, struct sess *sp) sp->vcl = GetVCL(); AZ(pthread_mutex_unlock(&sessmtx)); - done = http_Dissect(sp->http, sp->fd, 1); + done = http_DissectRequest(sp->http, sp->fd); if (done != 0) { RES_Error(w, sp, done, NULL); goto out; diff --git a/varnish-cache/include/stat_field.h b/varnish-cache/include/stat_field.h index d9e69e36..d8c2c2dd 100644 --- a/varnish-cache/include/stat_field.h +++ b/varnish-cache/include/stat_field.h @@ -21,3 +21,5 @@ MAC_STAT(n_wrk_create, uint64_t, "u", "N worker threads created"); MAC_STAT(n_wrk_failed, uint64_t, "u", "N worker threads not created"); MAC_STAT(n_wrk_short, uint64_t, "u", "N worker threads shortages"); MAC_STAT(n_wrk_busy, uint64_t, "u", "N busy worker threads"); + +MAC_STAT(losthdr, uint64_t, "u", "HTTP header overflows"); -- 2.39.5