Commit 9e4e9395 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Handle HTTP1.0 style "until EOF" data transmissions for 200 responses.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@3291 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 7a120ed7
...@@ -305,8 +305,8 @@ http_splitheader(struct http *hp, int req) ...@@ -305,8 +305,8 @@ http_splitheader(struct http *hp, int req)
* Receive another character * Receive another character
*/ */
static void static int
http_rxchar(struct http *hp, int n) http_rxchar_eof(struct http *hp, int n)
{ {
int i; int i;
struct pollfd pfd[1]; struct pollfd pfd[1];
...@@ -319,11 +319,23 @@ http_rxchar(struct http *hp, int n) ...@@ -319,11 +319,23 @@ http_rxchar(struct http *hp, int n)
assert(i > 0); assert(i > 0);
assert(hp->prxbuf < hp->nrxbuf); assert(hp->prxbuf < hp->nrxbuf);
i = read(hp->fd, hp->rxbuf + hp->prxbuf, n); i = read(hp->fd, hp->rxbuf + hp->prxbuf, n);
if (i == 0)
return (i);
assert(i > 0); assert(i > 0);
hp->prxbuf += i; hp->prxbuf += i;
hp->rxbuf[hp->prxbuf] = '\0'; hp->rxbuf[hp->prxbuf] = '\0';
n -= i; n -= i;
} }
return (1);
}
static void
http_rxchar(struct http *hp, int n)
{
int i;
i = http_rxchar_eof(hp, n);
assert(i > 0);
} }
/********************************************************************** /**********************************************************************
...@@ -331,7 +343,7 @@ http_rxchar(struct http *hp, int n) ...@@ -331,7 +343,7 @@ http_rxchar(struct http *hp, int n)
*/ */
static void static void
http_swallow_body(struct http *hp, char * const *hh) http_swallow_body(struct http *hp, char * const *hh, int body)
{ {
char *p, *q; char *p, *q;
int i, l, ll; int i, l, ll;
...@@ -344,7 +356,8 @@ http_swallow_body(struct http *hp, char * const *hh) ...@@ -344,7 +356,8 @@ http_swallow_body(struct http *hp, char * const *hh)
hp->body = q = hp->rxbuf + hp->prxbuf; hp->body = q = hp->rxbuf + hp->prxbuf;
http_rxchar(hp, l); http_rxchar(hp, l);
vtc_dump(hp->vl, 4, "body", hp->body); vtc_dump(hp->vl, 4, "body", hp->body);
ll = l; sprintf(hp->bodylen, "%d", l);
return;
} }
p = http_find_header(hh, "transfer-encoding"); p = http_find_header(hh, "transfer-encoding");
if (p != NULL && !strcmp(p, "chunked")) { if (p != NULL && !strcmp(p, "chunked")) {
...@@ -374,7 +387,17 @@ http_swallow_body(struct http *hp, char * const *hh) ...@@ -374,7 +387,17 @@ http_swallow_body(struct http *hp, char * const *hh)
break; break;
} }
vtc_dump(hp->vl, 4, "body", hp->body); vtc_dump(hp->vl, 4, "body", hp->body);
sprintf(hp->bodylen, "%d", ll);
return;
} }
if (body) {
hp->body = q = hp->rxbuf + hp->prxbuf;
do {
i = http_rxchar_eof(hp, 1);
ll += i;
} while (i > 0);
vtc_dump(hp->vl, 4, "rxeof", hp->body);
}
sprintf(hp->bodylen, "%d", ll); sprintf(hp->bodylen, "%d", ll);
} }
...@@ -433,7 +456,11 @@ cmd_http_rxresp(CMD_ARGS) ...@@ -433,7 +456,11 @@ cmd_http_rxresp(CMD_ARGS)
vtc_log(hp->vl, 3, "rxresp"); vtc_log(hp->vl, 3, "rxresp");
http_rxhdr(hp); http_rxhdr(hp);
http_splitheader(hp, 0); http_splitheader(hp, 0);
http_swallow_body(hp, hp->resp); if (!strcmp(hp->resp[1], "200"))
http_swallow_body(hp, hp->resp, 1);
else
http_swallow_body(hp, hp->resp, 0);
vtc_log(hp->vl, 4, "bodylen = %s", hp->bodylen);
} }
/********************************************************************** /**********************************************************************
...@@ -531,7 +558,8 @@ cmd_http_rxreq(CMD_ARGS) ...@@ -531,7 +558,8 @@ cmd_http_rxreq(CMD_ARGS)
vtc_log(hp->vl, 3, "rxreq"); vtc_log(hp->vl, 3, "rxreq");
http_rxhdr(hp); http_rxhdr(hp);
http_splitheader(hp, 1); http_splitheader(hp, 1);
http_swallow_body(hp, hp->req); http_swallow_body(hp, hp->req, 0);
vtc_log(hp->vl, 4, "bodylen = %s", hp->bodylen);
} }
/********************************************************************** /**********************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment