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) ...@@ -137,34 +137,42 @@ res_dorange(struct sess *sp, const char *r, unsigned *plow, unsigned *phigh)
if (strncmp(r, "bytes=", 6)) if (strncmp(r, "bytes=", 6))
return; return;
r += 6; r += 6;
printf("-----------------RANGE: <%s>\n", r);
/* The low end of range */
low = 0; low = 0;
high = 0; if (!vct_isdigit(*r) && *r != '-')
if (!vct_isdigit(*r))
return; return;
while (vct_isdigit(*r)) { while (vct_isdigit(*r)) {
low *= 10; low *= 10;
low += *r - '0'; low += *r - '0';
r++; r++;
} }
if (low >= sp->obj->len)
return;
if (*r != '-') if (*r != '-')
return; return;
r++; r++;
if (!vct_isdigit(*r))
return; /* The high end of range */
while (vct_isdigit(*r)) { if (vct_isdigit(*r)) {
high *= 10; high = 0;
high += *r - '0'; while (vct_isdigit(*r)) {
r++; high *= 10;
} high += *r - '0';
r++;
}
} else
high = sp->obj->len - 1;
if (*r != '\0') if (*r != '\0')
return; return;
printf("-----------------RANGE: %u %u\n", low, high);
if (high >= sp->obj->len) if (high >= sp->obj->len)
high = sp->obj->len - 1; high = sp->obj->len;
if (low == 0 && high >= sp->obj->len)
return;
if (low > high)
return;
http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp, http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp,
"Content-Range: bytes %u-%u/%u", low, high, sp->obj->len); "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) ...@@ -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, http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp,
"Content-Length: %u", 1 + high - low); "Content-Length: %u", 1 + high - low);
http_SetResp(sp->wrk->resp, "HTTP/1.1", "206", "Partial Content"); http_SetResp(sp->wrk->resp, "HTTP/1.1", "206", "Partial Content");
*plow = low; *plow = low;
*phigh = high; *phigh = high;
} }
......
...@@ -51,9 +51,39 @@ client c1 { ...@@ -51,9 +51,39 @@ client c1 {
expect resp.status == 206 expect resp.status == 206
expect resp.bodylen == 10 expect resp.bodylen == 10
txreq -hdr "Range: bytes=90-101" txreq -hdr "Range: bytes=90-"
rxresp rxresp
expect resp.status == 206 expect resp.status == 206
expect resp.bodylen == 10 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 } -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