[master] d921b1f26 Ensure we don't override Content-Encoding in a 304 conditional fetch

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Fri Apr 10 14:11:07 UTC 2020


commit d921b1f263ba7403427cc9f8c4e82ec05469b90a
Author: Dag Haavi Finstad <daghf at 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 036108954..88f5b6e53 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -308,9 +308,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


More information about the varnish-commit mailing list