[master] e8e089f Set Vary: Accept-Encoding if we munge the gzip status.
Poul-Henning Kamp
phk at FreeBSD.org
Wed Aug 27 09:59:57 CEST 2014
commit e8e089fc1968ee147fb06c60e3caae568bd11e40
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Aug 27 07:59:17 2014 +0000
Set Vary: Accept-Encoding if we munge the gzip status.
Patch by: fgs (with minor modifications)
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 9de6cfc..0d6c958 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1242,7 +1242,7 @@ enum body_status RFC2616_Body(struct busyobj *, struct dstat *);
unsigned RFC2616_Req_Gzip(const struct http *);
int RFC2616_Do_Cond(const struct req *sp);
void RFC2616_Weaken_Etag(struct http *hp);
-
+void RFC2616_Vary_AE(struct http *hp);
/* stevedore.c */
int STV_NewObject(struct busyobj *, const char *hint, unsigned len);
diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index 5fa6835..2963b95 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -165,6 +165,8 @@ vfp_esi_gzip_init(struct vfp_ctx *vc, struct vfp_entry *vfe)
http_Unset(vc->http, H_Content_Encoding);
http_SetHeader(vc->http, "Content-Encoding: gzip");
+ RFC2616_Vary_AE(vc->http);
+
return (VFP_OK);
}
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index 5433fa4..1e5b806 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -492,6 +492,9 @@ vfp_gzip_init(struct vfp_ctx *vc, struct vfp_entry *vfe)
if (vfe->vfp->priv2 == VFP_GZIP)
http_SetHeader(vc->http, "Content-Encoding: gzip");
+ if (vfe->vfp->priv2 == VFP_GZIP || vfe->vfp->priv2 == VFP_TESTGUNZIP)
+ RFC2616_Vary_AE(vc->http);
+
return (VFP_OK);
}
diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c
index 0f9292a..75f74b5 100644
--- a/bin/varnishd/cache/cache_rfc2616.c
+++ b/bin/varnishd/cache/cache_rfc2616.c
@@ -387,3 +387,20 @@ RFC2616_Weaken_Etag(struct http *hp)
http_Unset(hp, H_ETag);
http_PrintfHeader(hp, "ETag: W/%s", p);
}
+
+/*--------------------------------------------------------------------*/
+
+void
+RFC2616_Vary_AE(struct http *hp)
+{
+ char *vary;
+
+ if (http_GetHdrData(hp, H_Vary, "Accept-Encoding", NULL))
+ return;
+ if (http_GetHdr(hp, H_Vary, &vary)) {
+ http_Unset(hp, H_Vary);
+ http_PrintfHeader(hp, "Vary: %s, Accept-Encoding", vary);
+ } else {
+ http_SetHeader(hp, "Vary: Accept-Encoding");
+ }
+}
diff --git a/bin/varnishtest/tests/e00028.vtc b/bin/varnishtest/tests/e00028.vtc
new file mode 100644
index 0000000..8841067
--- /dev/null
+++ b/bin/varnishtest/tests/e00028.vtc
@@ -0,0 +1,98 @@
+varnishtest "Test Vary with ESI and gzip/gunzip"
+
+server s1 {
+ rxreq
+ txresp -body "foo"
+ rxreq
+ txresp -gzipbody "bar"
+ rxreq
+ txresp -body "baz"
+ rxreq
+ txresp -hdr "Vary: qux" -gzipbody "qux"
+ rxreq
+ txresp -hdr "Vary: fubar, Accept-Encoding" -gzipbody "fubar"
+ rxreq
+ txresp -gzipbody "foobar"
+ rxreq
+ txresp -hdr "Vary: foobaz" -gzipbody "foobaz"
+ rxreq
+ txresp -hdr "Vary: fooqux, Accept-Encoding" -gzipbody "fooqux"
+} -start
+
+varnish v1 -vcl+backend {
+ sub vcl_backend_response {
+ set beresp.do_esi = true;
+ if (bereq.url ~ "/baz") {
+ set beresp.do_gzip = true;
+ } elif (bereq.url ~ "/foo(bar|baz|qux)") {
+ set beresp.do_gunzip = true;
+ }
+ }
+} -start
+
+client c1 {
+ txreq -url /foo
+ rxresp
+ expect resp.body == "foo"
+ expect resp.http.Vary == <undef>
+ txreq -url /foo -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.body == "foo"
+ expect resp.http.Vary == <undef>
+ txreq -url /bar
+ rxresp
+ expect resp.body == "bar"
+ expect resp.http.Vary == "Accept-Encoding"
+ txreq -url /bar -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.bodylen == 34
+ expect resp.http.Vary == "Accept-Encoding"
+ txreq -url /baz
+ rxresp
+ expect resp.body == "baz"
+ expect resp.http.Vary == "Accept-Encoding"
+ txreq -url /baz -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.bodylen == 34
+ expect resp.http.Vary == "Accept-Encoding"
+ txreq -url /qux
+ rxresp
+ expect resp.body == "qux"
+ expect resp.http.Vary == "qux, Accept-Encoding"
+ txreq -url /qux -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.bodylen == 34
+ expect resp.http.Vary == "qux, Accept-Encoding"
+ txreq -url /fubar
+ rxresp
+ expect resp.body == "fubar"
+ expect resp.http.Vary == "fubar, Accept-Encoding"
+ txreq -url /fubar -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.bodylen == 36
+ expect resp.http.Vary == "fubar, Accept-Encoding"
+ txreq -url /foobar
+ rxresp
+ expect resp.body == "foobar"
+ expect resp.http.Vary == <undef>
+ txreq -url /foobar -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.body == "foobar"
+ expect resp.http.Vary == <undef>
+ txreq -url /foobaz
+ rxresp
+ expect resp.body == "foobaz"
+ expect resp.http.Vary == "foobaz"
+ txreq -url /foobaz -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.body == "foobaz"
+ expect resp.http.Vary == "foobaz"
+ txreq -url /fooqux
+ rxresp
+ expect resp.body == "fooqux"
+ expect resp.http.Vary == "fooqux, Accept-Encoding"
+ txreq -url /fooqux -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.body == "fooqux"
+ expect resp.http.Vary == "fooqux, Accept-Encoding"
+} -run
diff --git a/bin/varnishtest/tests/g00007.vtc b/bin/varnishtest/tests/g00007.vtc
new file mode 100644
index 0000000..276cbd1
--- /dev/null
+++ b/bin/varnishtest/tests/g00007.vtc
@@ -0,0 +1,97 @@
+varnishtest "Test Vary with gzip/gunzip"
+
+server s1 {
+ rxreq
+ txresp -body "foo"
+ rxreq
+ txresp -gzipbody "bar"
+ rxreq
+ txresp -body "baz"
+ rxreq
+ txresp -hdr "Vary: qux" -gzipbody "qux"
+ rxreq
+ txresp -hdr "Vary: fubar, Accept-Encoding" -gzipbody "fubar"
+ rxreq
+ txresp -gzipbody "foobar"
+ rxreq
+ txresp -hdr "Vary: foobaz" -gzipbody "foobaz"
+ rxreq
+ txresp -hdr "Vary: fooqux, Accept-Encoding" -gzipbody "fooqux"
+} -start
+
+varnish v1 -vcl+backend {
+ sub vcl_backend_response {
+ if (bereq.url ~ "/baz") {
+ set beresp.do_gzip = true;
+ } elif (bereq.url ~ "/foo(bar|baz|qux)") {
+ set beresp.do_gunzip = true;
+ }
+ }
+} -start
+
+client c1 {
+ txreq -url /foo
+ rxresp
+ expect resp.body == "foo"
+ expect resp.http.Vary == <undef>
+ txreq -url /foo -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.body == "foo"
+ expect resp.http.Vary == <undef>
+ txreq -url /bar
+ rxresp
+ expect resp.body == "bar"
+ expect resp.http.Vary == "Accept-Encoding"
+ txreq -url /bar -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.bodylen == 26
+ expect resp.http.Vary == "Accept-Encoding"
+ txreq -url /baz
+ rxresp
+ expect resp.body == "baz"
+ expect resp.http.Vary == "Accept-Encoding"
+ txreq -url /baz -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.bodylen == 23
+ expect resp.http.Vary == "Accept-Encoding"
+ txreq -url /qux
+ rxresp
+ expect resp.body == "qux"
+ expect resp.http.Vary == "qux, Accept-Encoding"
+ txreq -url /qux -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.bodylen == 26
+ expect resp.http.Vary == "qux, Accept-Encoding"
+ txreq -url /fubar
+ rxresp
+ expect resp.body == "fubar"
+ expect resp.http.Vary == "fubar, Accept-Encoding"
+ txreq -url /fubar -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.bodylen == 28
+ expect resp.http.Vary == "fubar, Accept-Encoding"
+ txreq -url /foobar
+ rxresp
+ expect resp.body == "foobar"
+ expect resp.http.Vary == <undef>
+ txreq -url /foobar -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.body == "foobar"
+ expect resp.http.Vary == <undef>
+ txreq -url /foobaz
+ rxresp
+ expect resp.body == "foobaz"
+ expect resp.http.Vary == "foobaz"
+ txreq -url /foobaz -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.body == "foobaz"
+ expect resp.http.Vary == "foobaz"
+ txreq -url /fooqux
+ rxresp
+ expect resp.body == "fooqux"
+ expect resp.http.Vary == "fooqux, Accept-Encoding"
+ txreq -url /fooqux -hdr "Accept-Encoding: gzip"
+ rxresp
+ expect resp.body == "fooqux"
+ expect resp.http.Vary == "fooqux, Accept-Encoding"
+} -run
More information about the varnish-commit
mailing list