[master] bb098e3f0 range: Check content-range unsatisfied-range

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Sep 1 14:08:06 UTC 2021


commit bb098e3f09f3c93454a305e0e32f63829af6148d
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Wed Sep 1 15:55:24 2021 +0200

    range: Check content-range unsatisfied-range
    
    And while at it add coverage for `content-range: bytes */*` for good
    measure.
    
    Fixes #3683

diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 701ff3a81..35f0f4a67 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -898,8 +898,6 @@ http_GetContentRange(const struct http *hp, ssize_t *lo, ssize_t *hi)
 	if (*lo > *hi)
 		return (-2);
 	assert(cl >= -1);
-	if (cl == -1)
-		return (-1);
 	if (*lo >= cl || *hi >= cl)
 		return (-2);
 	AN(cl);
diff --git a/bin/varnishd/cache/cache_range.c b/bin/varnishd/cache/cache_range.c
index b9944aa6e..71793ab4e 100644
--- a/bin/varnishd/cache/cache_range.c
+++ b/bin/varnishd/cache/cache_range.c
@@ -287,7 +287,7 @@ VRG_CheckBo(struct busyobj *bo)
 		return (-1);
 	}
 
-	if (crlo < 0 || crhi < 0) {
+	if (crlo < 0 && crhi < 0 && crlen < 0) {
 		AZ(http_GetHdr(bo->beresp, H_Content_Range, NULL));
 		return (0);
 	}
@@ -297,6 +297,13 @@ VRG_CheckBo(struct busyobj *bo)
 		return (-1);
 	}
 
+	if (crlo < 0) {		// Content-Range: bytes */123
+		assert(crhi < 0);
+		assert(crlen > 0);
+		crlo = 0;
+		crhi = crlen - 1;
+	}
+
 #define RANGE_CHECK(val, op, crval, what)			\
 	do {							\
 		if (val >= 0 && !(val op crval)) {		\
diff --git a/bin/varnishtest/tests/c00034.vtc b/bin/varnishtest/tests/c00034.vtc
index d34b91cbe..df6bd6056 100644
--- a/bin/varnishtest/tests/c00034.vtc
+++ b/bin/varnishtest/tests/c00034.vtc
@@ -246,9 +246,18 @@ server s1 {
 	txresp -status 206 -hdr "content-range: bytes 10-19/100" -bodylen 40
 
 	rxreq
-	expect req.url == "/4"
+	expect req.url == "/?unexpected=content-range"
 	expect req.http.range == <undef>
 	txresp -hdr "content-range: bytes 0-49/100" -bodylen 40
+
+	rxreq
+	expect req.url == "/?unexpected=unsatisfied-range"
+	expect req.http.range == <undef>
+	txresp -hdr "content-range: bytes */100" -bodylen 100
+
+	rxreq
+	expect req.http.range == "bytes=0-0"
+	txresp -hdr "content-range: bytes */*" -bodylen 100
 } -start
 
 varnish v1 -vcl+backend {
@@ -270,7 +279,15 @@ client c8 {
 	rxresp
 	expect resp.status == 503
 
-	txreq -url /4
+	txreq -url "/?unexpected=content-range"
+	rxresp
+	expect resp.status == 503
+
+	txreq -url "/?unexpected=unsatisfied-range"
+	rxresp
+	expect resp.status == 503
+
+	txreq -hdr "range: bytes=0-0" -hdr "return: pass"
 	rxresp
 	expect resp.status == 503
 } -run
@@ -288,7 +305,7 @@ varnish v1 -vcl+backend {
 	}
 }
 
-client c1 {
+client c9 {
 	txreq -url /5
 	rxresp
 	expect resp.status == 200


More information about the varnish-commit mailing list