[4.0] e04394c Copy the status code, proto, status string and response message on backend IMS.

Martin Blix Grydeland martin at varnish-software.com
Tue Jun 24 11:31:39 CEST 2014


commit e04394c7205547193d188ca5d18e8361e57c838d
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Fri Apr 25 11:11:13 2014 +0200

    Copy the status code, proto, status string and response message on
    backend IMS.
    
    When revalidating using backend IMS, copy the status code, status
    code, status string and response message from the original object into
    the new revalidated object. This makes sure that none of the 304
    message fields gets applied to the new revalidated object.
    
    Fixes: #1485

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index e61a007..dded999 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -356,9 +356,9 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
 	AZ(bo->do_esi);
 
 	if (bo->ims_obj != NULL && bo->beresp->status == 304) {
-		bo->beresp->status = 200;
 		http_Merge(bo->ims_obj->http, bo->beresp,
 		    bo->ims_obj->changed_gzip);
+		assert(bo->beresp->status == 200);
 		do_ims = 1;
 	} else
 		do_ims = 0;
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 6898987..7fe6c9f 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -637,7 +637,9 @@ http_FilterResp(const struct http *fm, struct http *to, unsigned how)
 }
 
 /*--------------------------------------------------------------------
- * Merge two HTTP headers the "wrong" way.
+ * Merge two HTTP headers the "wrong" way. Used by backend IMS to
+ * merge in the headers of the validated object with the headers of
+ * the 304 response.
  */
 
 void
@@ -646,6 +648,11 @@ http_Merge(const struct http *fm, struct http *to, int not_ce)
 	unsigned u, v;
 	const char *p;
 
+	to->status = fm->status;
+	http_SetH(to, HTTP_HDR_PROTO, fm->hd[HTTP_HDR_PROTO].b);
+	http_SetH(to, HTTP_HDR_STATUS, fm->hd[HTTP_HDR_STATUS].b);
+	http_SetH(to, HTTP_HDR_RESPONSE, fm->hd[HTTP_HDR_RESPONSE].b);
+
 	for (u = HTTP_HDR_FIRST; u < fm->nhd; u++)
 		fm->hdf[u] |= HDF_MARKER;
 	if (not_ce) {
diff --git a/bin/varnishtest/tests/r01485.vtc b/bin/varnishtest/tests/r01485.vtc
new file mode 100644
index 0000000..caf267a
--- /dev/null
+++ b/bin/varnishtest/tests/r01485.vtc
@@ -0,0 +1,32 @@
+varnishtest "#1485: Wrong response reason phrase"
+
+server s1 {
+	rxreq
+	txresp -hdr "Etag: foo"
+
+	rxreq
+	expect req.http.If-None-Match == "foo"
+	txresp -status 304 -msg "Not Modified"
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_backend_response {
+		set beresp.ttl = 1ms;
+		set beresp.grace = 0s;
+		set beresp.keep = 1h;
+	}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 200
+	expect resp.msg == "OK"
+
+	delay 0.1
+
+	txreq
+	rxresp
+	expect resp.status == 200
+	expect resp.msg == "OK"
+} -run



More information about the varnish-commit mailing list