r4700 - in trunk/varnish-cache/bin: varnishd varnishtest/tests

phk at varnish-cache.org phk at varnish-cache.org
Wed Apr 21 07:53:41 CEST 2010


Author: phk
Date: 2010-04-21 07:53:41 +0200 (Wed, 21 Apr 2010)
New Revision: 4700

Modified:
   trunk/varnish-cache/bin/varnishd/cache_response.c
   trunk/varnish-cache/bin/varnishtest/tests/c00034.vtc
Log:
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.




Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c	2010-04-20 16:06:38 UTC (rev 4699)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c	2010-04-21 05:53:41 UTC (rev 4700)
@@ -137,41 +137,51 @@
 	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)
+		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);
 	http_Unset(sp->wrk->resp, H_Content_Length);
 	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;
 }

Modified: trunk/varnish-cache/bin/varnishtest/tests/c00034.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/c00034.vtc	2010-04-20 16:06:38 UTC (rev 4699)
+++ trunk/varnish-cache/bin/varnishtest/tests/c00034.vtc	2010-04-21 05:53:41 UTC (rev 4700)
@@ -51,9 +51,39 @@
 	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
 




More information about the varnish-commit mailing list