Attached is a new diff based on our discussion on irc.
This is now handled within the vfps and thus will happen after
vcl_backend_response and the inserted object will include the Vary header.

The caveat with this approach, at least in the current implementation, is
that disabling http_gzip_support won't have any effect on existing objects
but I can't see this being an issue.



On Tue, Aug 26, 2014 at 1:26 PM, Poul-Henning Kamp <[email protected]>
wrote:

> --------
> In message <CAJV_h0bfQstBU=hQ60=
> [email protected]>
> , Federico Schwindt writes:
>
> >Does this mean that doing it in vfp_gzip_init() or cache_gzip.c would be
> >appropriate or preferred?
>
> I probably lost context for "it" here :-)
>
> But if you look in -trunk, you'll see for instance vfp_gzip_init()
> doing:
>
>         if (vfe->vfp->priv2 == VFP_GUNZIP || vfe->vfp->priv2 == VFP_GZIP) {
>                 http_Unset(vc->http, H_Content_Encoding);
>                 http_Unset(vc->http, H_Content_Length);
>                 RFC2616_Weaken_Etag(vc->http);
>         }
>
>
> --
> Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
> [email protected]         | TCP/IP since RFC 956
> FreeBSD committer       | BSD since 4.3-tahoe
> Never attribute to malice what can adequately be explained by incompetence.
>
diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index 5fa6835..2ec8a40 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -143,6 +143,7 @@ static enum vfp_status __match_proto__(vfp_init_f)
 vfp_esi_gzip_init(struct vfp_ctx *vc, struct vfp_entry *vfe)
 {
 	struct vef_priv *vef;
+	char *vary;
 
 	CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
 	CHECK_OBJ_NOTNULL(vc->esi_req, HTTP_MAGIC);
@@ -165,6 +166,15 @@ 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");
 
+	if (http_GetHdrData(vc->http, H_Vary, "Accept-Encoding", NULL))
+		;
+	else if (http_GetHdr(vc->http, H_Vary, &vary)) {
+		http_Unset(vc->http, H_Vary);
+		http_PrintfHeader(vc->http,
+		    "Vary: %s, Accept-Encoding", vary);
+	} else
+		http_SetHeader(vc->http, "Vary: Accept-Encoding");
+
 	return (VFP_OK);
 }
 
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index 5433fa4..dd1b79d 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -457,6 +457,7 @@ static enum vfp_status __match_proto__(vfp_init_f)
 vfp_gzip_init(struct vfp_ctx *vc, struct vfp_entry *vfe)
 {
 	struct vgz *vg;
+	char *vary;
 
 	CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
 	CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
@@ -492,6 +493,18 @@ 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) {
+		if (http_GetHdrData(vc->http, H_Vary, "Accept-Encoding",
+		    NULL))
+			;
+		else if (http_GetHdr(vc->http, H_Vary, &vary)) {
+			http_Unset(vc->http, H_Vary);
+			http_PrintfHeader(vc->http,
+			    "Vary: %s, Accept-Encoding", vary);
+		} else
+			http_SetHeader(vc->http, "Vary: Accept-Encoding");
+	}
+
 	return (VFP_OK);
 }
 
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
_______________________________________________
varnish-dev mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev

Reply via email to