Commit f8b50ca9 authored by Geoff Simmons's avatar Geoff Simmons

Fix handling of 304 backend responses.

Set the OF_CHGGZIP flag to indicate that:
- The ETag in a client response must be weakened if the response
  body differs from the fetched response.
- Any Content-Encoding header in the fetched 304 response should
  be removed.
parent c37a1594
# looks like -*- vcl -*-
varnishtest "Backend IMS and brotli de-/compression"
# cf. Varnish g00006.vtc
server s1 {
rxreq
expect req.url == /1
txresp -hdr "Last-Modified: Wed, 11 Sep 2013 13:36:55 GMT" \
-hdr {ETag: "foozle"} \
-body {The quick brown fox jumps over the lazy dog}
rxreq
expect req.url == /1
expect req.http.if-modified-since == "Wed, 11 Sep 2013 13:36:55 GMT"
txresp -status 304 \
-hdr {ETag: "fizle"} \
-nolen
rxreq
expect req.url == /2
txresp -hdr "Last-Modified: Wed, 11 Sep 2013 13:36:55 GMT" \
-hdr {ETag: "foobar"} -hdr "Content-Encoding: br" \
-body { The quick brown fox jumps over the lazy dog}
rxreq
expect req.url == /2
expect req.http.if-modified-since == "Wed, 11 Sep 2013 13:36:55 GMT"
txresp -status 304 -hdr "Content-Encoding: br" \
-hdr {ETag: "snafu"} \
-nolen
} -start
varnish v1 -vcl+backend {
import ${vmod_brotli};
sub vcl_backend_response {
set beresp.http.foobar = beresp.http.content-encoding;
if (bereq.url == "/1") {
set beresp.filters = "br";
} else {
set beresp.filters = "unbr";
}
set beresp.ttl = 1s;
set beresp.grace = 0s;
set beresp.keep = 60s;
}
} -start
client c1 {
txreq -url /1 -hdr "Accept-Encoding: br"
rxresp
expect resp.http.content-encoding == "br"
expect resp.http.foobar == ""
expect resp.http.etag == {W/"foozle"}
expect resp.bodylen == 47
expect resp.body == " The quick brown fox jumps over the lazy dog"
delay 1
txreq -url /1 -hdr "Accept-Encoding: br"
rxresp
expect resp.http.content-encoding == "br"
expect resp.http.foobar == "br"
expect resp.http.etag == {W/"fizle"}
expect resp.bodylen == 47
expect resp.body == " The quick brown fox jumps over the lazy dog"
delay .2
txreq -url /2
rxresp
expect resp.http.content-encoding == <undef>
expect resp.http.foobar == "br"
expect resp.http.etag == {W/"foobar"}
expect resp.bodylen == 43
expect resp.body == "The quick brown fox jumps over the lazy dog"
delay 1
txreq -url /2
rxresp
expect resp.http.content-encoding == <undef>
# Here we see the C-E of the IMS OBJ
expect resp.http.foobar == ""
expect resp.http.etag == {W/"snafu"}
expect resp.bodylen == 43
expect resp.body == "The quick brown fox jumps over the lazy dog"
} -run
......@@ -349,6 +349,7 @@ vfp_br_init(struct vfp_ctx *ctx, struct vfp_entry *ent)
http_Unset(ctx->resp, H_Content_Encoding);
http_Unset(ctx->resp, H_Content_Length);
RFC2616_Weaken_Etag(ctx->resp);
ctx->obj_flags |= OF_CHGGZIP;
if (settings->which == ENC) {
http_SetHeader(ctx->resp, "Content-Encoding: br");
......
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