Mailing List Archive

[6.0] 66ad64fe6 Ensure we don't override Content-Encoding in a 304 conditional fetch
commit 66ad64fe6b9d824429639095e726ffb28a091b92
Author: Dag Haavi Finstad <daghf@varnish-software.com>
Date: Thu Nov 21 11:50:23 2019 +0100

Ensure we don't override Content-Encoding in a 304 conditional fetch

Test inspired by Carlos Abalde

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 970a10011..bd02fc822 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -267,9 +267,9 @@ vbf_304_logic(struct busyobj *bo)
* the IMS fetch, and we must weaken any
* new ETag we get.
*/
- http_Unset(bo->beresp, H_Content_Encoding);
RFC2616_Weaken_Etag(bo->beresp);
}
+ http_Unset(bo->beresp, H_Content_Encoding);
http_Unset(bo->beresp, H_Content_Length);
HTTP_Merge(bo->wrk, bo->stale_oc, bo->beresp);
assert(http_IsStatus(bo->beresp, 200));
diff --git a/bin/varnishtest/tests/r03169.vtc b/bin/varnishtest/tests/r03169.vtc
new file mode 100644
index 000000000..650b15c83
--- /dev/null
+++ b/bin/varnishtest/tests/r03169.vtc
@@ -0,0 +1,61 @@
+varnishtest "Ensure we don't override Content-Encoding on a cond fetch"
+
+server s1 {
+ rxreq
+ txresp -hdr {ETag: "foo"} -body {****}
+
+ rxreq
+ expect req.http.If-None-Match == {"foo"}
+ txresp -status 304 -hdr {ETag: W/"foo"} -hdr "Content-Encoding: gzip"
+
+ rxreq
+ expect req.url == "/1"
+ txresp -hdr {Etag: "bar"} -gzipbody {asdf}
+
+ rxreq
+ expect req.url == "/1"
+ expect req.http.If-None-Match == {"bar"}
+ txresp -status 304
+
+} -start
+
+varnish v1 -vcl+backend {
+ sub vcl_backend_response {
+ set beresp.ttl = 1s;
+ set beresp.grace = 0s;
+ set beresp.keep = 1d;
+ }
+} -start
+
+client c1 {
+ txreq -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.ETag == {"foo"}
+ expect resp.http.Content-Length == "4"
+ expect resp.http.Content-Encoding == <undef>
+
+ delay 1.5
+
+ txreq -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.ETag == {W/"foo"}
+ expect resp.http.Content-Length == "4"
+ expect resp.http.Content-Encoding == <undef>
+
+ # Also check that we're still OK in the general case
+ txreq -url "/1" -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.ETag == {"bar"}
+ expect resp.http.Content-Encoding == "gzip"
+
+ delay 1.5
+
+ txreq -url "/1" -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.ETag == {"bar"}
+ expect resp.http.Content-Encoding == "gzip"
+} -run
\ No newline at end of file
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit