From: phk Date: Fri, 28 Sep 2007 11:07:14 +0000 (+0000) Subject: Push the http structure out of the early bits of the reception code. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=723bf32814dda5517d19999338182193fbff0fc3;p=varnish Push the http structure out of the early bits of the reception code. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2052 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index 21bf9b97..01cd3bc5 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -563,28 +563,33 @@ http_DissectResponse(struct worker *w, struct http *hp, int fd) } /*-------------------------------------------------------------------- - * Return nonzero if we have a complete HTTP request. + * Check if we have a complete HTTP request or response yet between the + * two pointers given. + * + * Return values: + * -1 No, and you can nuke the (white-space) content. + * 0 No, keep trying + * >0 Yes, it is this many bytes long. */ static int -http_header_complete(struct http *hp) +http_header_complete(const char *b, const char *e) { - char *p; + const char *p; - CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC); - assert(*hp->rx.e == '\0'); + AN(b); + AN(e); + assert(b <= e); + assert(*e == '\0'); /* Skip any leading white space */ - for (p = hp->rx.b ; p < hp->rx.e && isspace(*p); p++) + for (p = b ; isspace(*p); p++) continue; - if (p >= hp->rx.e) { - hp->rx.e = hp->rx.b; - return (0); - } + if (*p == '\0') + return (-1); while (1) { - /* XXX: we could save location of all linebreaks for later */ p = strchr(p, '\n'); if (p == NULL) - return (0); /* XXX: Could cache p */ + return (0); p++; if (*p == '\r') p++; @@ -592,14 +597,7 @@ http_header_complete(struct http *hp) break; } p++; - WS_ReleaseP(hp->ws, hp->rx.e); - if (p != hp->rx.e) { - hp->pl.b = p; - hp->pl.e = hp->rx.e; - hp->rx.e = p; - } - /* XXX: Check this stuff... */ - return (1); + return (p - b); } /*--------------------------------------------------------------------*/ @@ -627,11 +625,23 @@ http_RecvPrep(struct http *hp) int http_RecvPrepAgain(struct http *hp) { + int i; http_RecvPrep(hp); if (hp->rx.b == hp->rx.e) return (0); - return (http_header_complete(hp)); + i = http_header_complete(hp->rx.b, hp->rx.e); + if (i == -1) + hp->rx.e = hp->rx.b; + if (i <= 0) + return (0); + WS_ReleaseP(hp->ws, hp->rx.e); + if (hp->rx.e != hp->rx.b + i) { + hp->pl.b = hp->rx.b + i; + hp->pl.e = hp->rx.e; + hp->rx.e = hp->pl.b; + } + return (i); } /*--------------------------------------------------------------------*/ @@ -656,9 +666,18 @@ http_RecvSome(int fd, struct http *hp) if (i > 0) { hp->rx.e += i; *hp->rx.e = '\0'; - if (http_header_complete(hp)) - return(0); - return (-1); + i = http_header_complete(hp->rx.b, hp->rx.e); + if (i == -1) + hp->rx.e = hp->rx.b; + if (i == 0) + return (-1); + WS_ReleaseP(hp->ws, hp->rx.e); + if (hp->rx.e != hp->rx.b + i) { + hp->pl.b = hp->rx.b + i; + hp->pl.e = hp->rx.e; + hp->rx.e = hp->pl.b; + } + return (0); } if (hp->rx.e != hp->rx.b) {