[master] 6a06d64 Get IMS and gzip/gunzip more correct:
Poul-Henning Kamp
phk at FreeBSD.org
Tue Aug 12 11:22:54 CEST 2014
commit 6a06d64d4d83215812e9f030877364ac6c1a9e9d
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Aug 12 09:22:00 2014 +0000
Get IMS and gzip/gunzip more correct:
If we gzip/gzunzipped the object, the C-E header we produced controls
and if the 304 contains an ETag, it must be weakened.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 47e4fa7..0f9605b 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -982,7 +982,7 @@ void http_MarkHeader(const struct http *, const char *hdr, unsigned hdrlen,
uint8_t flag);
void http_CollectHdr(struct http *hp, const char *hdr);
void http_VSL_log(const struct http *hp);
-void http_Merge(const struct http *fm, struct http *to, int not_ce);
+void http_Merge(const struct http *fm, struct http *to);
/* cache_http1_proto.c */
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 8b605ce..8c1d2a5 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -350,8 +350,16 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
AZ(bo->do_esi);
if (bo->ims_oc != NULL && http_IsStatus(bo->beresp, 304)) {
- http_Merge(bo->ims_obj->http, bo->beresp,
- ObjCheckFlag(bo->ims_oc, bo->stats, OF_CHGGZIP));
+ if (ObjCheckFlag(bo->ims_oc, bo->stats, OF_CHGGZIP)) {
+ /*
+ * If we changed the gzip status of the object
+ * the stored Content_Encoding controls and we
+ * must weaken any new ETag we get.
+ */
+ http_Unset(bo->beresp, H_Content_Encoding);
+ RFC2616_Weaken_Etag(bo->beresp);
+ }
+ http_Merge(bo->ims_obj->http, bo->beresp);
assert(http_IsStatus(bo->beresp, 200));
do_ims = 1;
} else
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 6dc5251..b788f89 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -785,7 +785,7 @@ http_FilterReq(struct http *to, const struct http *fm, unsigned how)
*/
void
-http_Merge(const struct http *fm, struct http *to, int not_ce)
+http_Merge(const struct http *fm, struct http *to)
{
unsigned u, v;
const char *p;
@@ -797,12 +797,6 @@ http_Merge(const struct http *fm, struct http *to, int not_ce)
for (u = HTTP_HDR_FIRST; u < fm->nhd; u++)
fm->hdf[u] |= HDF_MARKER;
- if (not_ce) {
- u = http_findhdr(fm,
- H_Content_Encoding[0] - 1, H_Content_Encoding + 1);
- if (u > 0)
- fm->hdf[u] &= ~HDF_MARKER;
- }
for (v = HTTP_HDR_FIRST; v < to->nhd; v++) {
p = strchr(to->hd[v].b, ':');
AN(p);
diff --git a/bin/varnishtest/tests/g00006.vtc b/bin/varnishtest/tests/g00006.vtc
index 740d4bd..cbae574 100644
--- a/bin/varnishtest/tests/g00006.vtc
+++ b/bin/varnishtest/tests/g00006.vtc
@@ -3,21 +3,29 @@ varnishtest "IMS'ing g[un]zip'ed objects"
server s1 {
rxreq
expect req.url == /1
- txresp -hdr "Last-Modified: Wed, 11 Sep 2013 13:36:55 GMT" -bodylen 20
+ txresp -hdr "Last-Modified: Wed, 11 Sep 2013 13:36:55 GMT" \
+ -hdr "ETag: foozle" \
+ -bodylen 20
rxreq
expect req.url == /1
expect req.http.if-modified-since == "Wed, 11 Sep 2013 13:36:55 GMT"
- txresp -status 304 -nolen
+ txresp -status 304 \
+ -hdr "ETag: fizle" \
+ -nolen
rxreq
expect req.url == /2
- txresp -hdr "Last-Modified: Wed, 11 Sep 2013 13:36:55 GMT" -gzipbody "012345678901234567"
+ txresp -hdr "Last-Modified: Wed, 11 Sep 2013 13:36:55 GMT" \
+ -hdr "ETag: foobar" \
+ -gzipbody "012345678901234567"
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: gzip,rot13" -nolen
+ txresp -status 304 -hdr "Content-Encoding: gzip,rot13" \
+ -hdr "ETag: snafu" \
+ -nolen
} -start
@@ -40,6 +48,7 @@ client c1 {
rxresp
expect resp.http.content-encoding == "gzip"
expect resp.http.foobar == ""
+ expect resp.http.etag == "W/foozle"
gunzip
expect resp.bodylen == 20
@@ -48,7 +57,8 @@ client c1 {
txreq -url /1 -hdr "Accept-Encoding: gzip"
rxresp
expect resp.http.content-encoding == "gzip"
- expect resp.http.foobar == ""
+ expect resp.http.foobar == "gzip"
+ expect resp.http.etag == "W/fizle"
gunzip
expect resp.bodylen == 20
@@ -59,6 +69,7 @@ client c1 {
expect resp.http.content-encoding == "<undef>"
expect resp.http.foobar == "gzip"
expect resp.bodylen == 18
+ expect resp.http.etag == "W/foobar"
delay 1
@@ -66,7 +77,8 @@ client c1 {
rxresp
expect resp.http.content-encoding == "<undef>"
# Here we see the C-E of the IMS OBJ
- expect resp.http.foobar == "gzip,rot13"
+ expect resp.http.foobar == ""
+ expect resp.http.etag == "W/snafu"
expect resp.bodylen == 18
} -run
More information about the varnish-commit
mailing list