]> err.no Git - varnish/commitdiff
Split http_Dissect() into http_DissectRequest() and http_DissectResponse()
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 11 Jul 2006 07:30:53 +0000 (07:30 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 11 Jul 2006 07:30:53 +0000 (07:30 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@420 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_fetch.c
varnish-cache/bin/varnishd/cache_http.c
varnish-cache/bin/varnishd/cache_pass.c
varnish-cache/bin/varnishd/cache_pool.c
varnish-cache/include/stat_field.h

index c7ffc8b596dc39c6296499df6156fb76a8e205ec..cd3b5ac632e4f9e7d2da087717587cf3a31c0b23 100644 (file)
@@ -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,
index e3364d668c988a24a3cabf8520319200d1d90374..997ac1e25e0233a60c22fb42c0f09cc445b49be8 100644 (file)
@@ -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);
 
index a3b326d3bd70eba8b036c905a6f32355b9a21daf..bd29e859d0c92399c15265bea776a3e3055932e7 100644 (file)
@@ -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)
 {
index 5872a16ebb79fe12984931b7b09a21fe6acfe452..0b0e19c2634095c1e7f92f9b08636155822bb820 100644 (file)
@@ -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));
index 4971db652c75dae158aab70891785eaf42dbd318..d4663777408c4dd3efca0d989739018d11aea4c9 100644 (file)
@@ -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;
index d9e69e36065dbe50aece131885a75f8b83f2d8ac..d8c2c2dd94c985920a0b3110ed59a845b0015cef 100644 (file)
@@ -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");