Commit 7ccd2400 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Tune Range: handling based on real-world sample:

Also support: bytes=-%d bytes=%d- bytes=-

And ignore plain wrong cases, such as starter past end of object or
end before start etc.




git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4700 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 7d836442
......@@ -137,34 +137,42 @@ res_dorange(struct sess *sp, const char *r, unsigned *plow, unsigned *phigh)
if (strncmp(r, "bytes=", 6))
return;
r += 6;
printf("-----------------RANGE: <%s>\n", r);
/* The low end of range */
low = 0;
high = 0;
if (!vct_isdigit(*r))
if (!vct_isdigit(*r) && *r != '-')
return;
while (vct_isdigit(*r)) {
low *= 10;
low += *r - '0';
r++;
}
if (low >= sp->obj->len)
return;
if (*r != '-')
return;
r++;
if (!vct_isdigit(*r))
return;
while (vct_isdigit(*r)) {
high *= 10;
high += *r - '0';
r++;
}
/* The high end of range */
if (vct_isdigit(*r)) {
high = 0;
while (vct_isdigit(*r)) {
high *= 10;
high += *r - '0';
r++;
}
} else
high = sp->obj->len - 1;
if (*r != '\0')
return;
printf("-----------------RANGE: %u %u\n", low, high);
if (high >= sp->obj->len)
high = sp->obj->len - 1;
if (low == 0 && high >= sp->obj->len)
return;
high = sp->obj->len;
if (low > high)
return;
http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp,
"Content-Range: bytes %u-%u/%u", low, high, sp->obj->len);
......@@ -172,6 +180,8 @@ res_dorange(struct sess *sp, const char *r, unsigned *plow, unsigned *phigh)
http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp,
"Content-Length: %u", 1 + high - low);
http_SetResp(sp->wrk->resp, "HTTP/1.1", "206", "Partial Content");
*plow = low;
*phigh = high;
}
......
......@@ -51,9 +51,39 @@ client c1 {
expect resp.status == 206
expect resp.bodylen == 10
txreq -hdr "Range: bytes=90-101"
txreq -hdr "Range: bytes=90-"
rxresp
expect resp.status == 206
expect resp.bodylen == 10
txreq -hdr "Range: bytes=-9"
rxresp
expect resp.status == 206
expect resp.bodylen == 10
txreq -hdr "Range: bytes=-"
rxresp
expect resp.status == 206
expect resp.bodylen == 100
txreq -hdr "Range: bytes=102-102"
rxresp
expect resp.status == 200
expect resp.bodylen == 100
txreq -hdr "Range: bytes=99-"
rxresp
expect resp.status == 206
expect resp.bodylen == 1
txreq -hdr "Range: bytes=99-70"
rxresp
expect resp.status == 200
expect resp.bodylen == 100
txreq -hdr "Range: bytes=-"
rxresp
expect resp.status == 206
expect resp.bodylen == 100
} -run
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