Commit e17acd8f authored by Poul-Henning Kamp's avatar Poul-Henning Kamp Committed by Tollef Fog Heen

Polish the chunked body fetcher. It still irks me that it does

one byte reads for the hex-length headers.

Conflicts:

	bin/varnishd/cache_fetch.c
parent 052053b1
...@@ -251,9 +251,9 @@ fetch_straight(struct sess *sp, struct http_conn *htc, ssize_t cl) ...@@ -251,9 +251,9 @@ fetch_straight(struct sess *sp, struct http_conn *htc, ssize_t cl)
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* Read a chunked HTTP object. * Read a chunked HTTP object.
*
* XXX: Reading one byte at a time is pretty pessimal. * XXX: Reading one byte at a time is pretty pessimal.
*/ */
static int static int
fetch_chunked(struct sess *sp, struct http_conn *htc) fetch_chunked(struct sess *sp, struct http_conn *htc)
...@@ -267,17 +267,18 @@ fetch_chunked(struct sess *sp, struct http_conn *htc) ...@@ -267,17 +267,18 @@ fetch_chunked(struct sess *sp, struct http_conn *htc)
do { do {
/* Skip leading whitespace */ /* Skip leading whitespace */
do { do {
i = HTC_Read(sp->wrk, htc, buf, 1); if (HTC_Read(sp->wrk, htc, buf, 1) <= 0)
if (i <= 0) return (-1);
return (i);
} while (vct_islws(buf[0])); } while (vct_islws(buf[0]));
if (!vct_ishex(buf[0]))
return (FetchError(sp,"chunked header non-hex"));
/* Collect hex digits, skipping leading zeros */ /* Collect hex digits, skipping leading zeros */
for (u = 1; u < sizeof buf; u++) { for (u = 1; u < sizeof buf; u++) {
do { do {
i = HTC_Read(sp->wrk, htc, buf + u, 1); if (HTC_Read(sp->wrk, htc, buf + u, 1) <= 0)
if (i <= 0) return (-1);
return (i);
} while (u == 1 && buf[0] == '0' && buf[u] == '0'); } while (u == 1 && buf[0] == '0' && buf[u] == '0');
if (!vct_ishex(buf[u])) if (!vct_ishex(buf[u]))
break; break;
...@@ -288,41 +289,32 @@ fetch_chunked(struct sess *sp, struct http_conn *htc) ...@@ -288,41 +289,32 @@ fetch_chunked(struct sess *sp, struct http_conn *htc)
} }
/* Skip trailing white space */ /* Skip trailing white space */
while(vct_islws(buf[u]) && buf[u] != '\n') { while(vct_islws(buf[u]) && buf[u] != '\n')
i = HTC_Read(sp->wrk, htc, buf + u, 1); if (HTC_Read(sp->wrk, htc, buf + u, 1) <= 0)
if (i <= 0) return (-1);
return (i);
}
if (buf[u] != '\n') { if (buf[u] != '\n')
return (FetchError(sp,"chunked header no NL")); return (FetchError(sp,"chunked header no NL"));
}
buf[u] = '\0';
buf[u] = '\0';
cl = fetch_number(buf, 16); cl = fetch_number(buf, 16);
if (cl < 0) { if (cl < 0)
return (FetchError(sp,"chunked header number syntax")); return (FetchError(sp,"chunked header number syntax"));
} else if (cl > 0) {
i = sp->wrk->vfp->bytes(sp, htc, cl); if (cl > 0 && sp->wrk->vfp->bytes(sp, htc, cl) <= 0)
if (i <= 0) return (-1);
return (-1);
}
i = HTC_Read(sp->wrk, htc, buf, 1); i = HTC_Read(sp->wrk, htc, buf, 1);
if (i <= 0) if (i <= 0)
return (-1); return (-1);
if (buf[0] == '\r') { if (buf[0] == '\r' && HTC_Read(sp->wrk, htc, buf, 1) <= 0)
i = HTC_Read(sp->wrk, htc, buf, 1); return (-1);
if (i <= 0)
return (-1);
}
if (buf[0] != '\n') if (buf[0] != '\n')
return (FetchError(sp,"chunked tail no NL")); return (FetchError(sp,"chunked tail no NL"));
} while (cl > 0); } while (cl > 0);
return (0); return (0);
} }
#undef CERR
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static int static int
......
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