[master] a5bf869 Don't send Content-Length on 304 responses.
Poul-Henning Kamp
phk at FreeBSD.org
Mon Jan 6 18:27:52 CET 2014
commit a5bf869f4fd5de53eb5e8c3084d5931154cc58d3
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Jan 6 17:26:39 2014 +0000
Don't send Content-Length on 304 responses.
It seems that browser writers also have trouble figuring out that
twisted logic in HTTP/1.1.
Fixes: #1404
Spotted by: Scoof
diff --git a/bin/varnishd/cache/cache_http1_deliver.c b/bin/varnishd/cache/cache_http1_deliver.c
index 65c25d5..974202d 100644
--- a/bin/varnishd/cache/cache_http1_deliver.c
+++ b/bin/varnishd/cache/cache_http1_deliver.c
@@ -207,6 +207,10 @@ V1D_Deliver(struct req *req)
/* In ESI mode, we can't know the aggregate length */
req->res_mode &= ~RES_LEN;
req->res_mode |= RES_ESI;
+ } else if (req->resp->status == 304) {
+ req->res_mode &= ~RES_LEN;
+ http_Unset(req->resp, H_Content_Length);
+ req->wantbody = 0;
} else if (req->obj->objcore->busyobj == NULL) {
/* XXX: Not happy with this convoluted test */
req->res_mode |= RES_LEN;
@@ -284,9 +288,6 @@ V1D_Deliver(struct req *req)
if (!(req->res_mode & RES_ESI_CHILD))
req->acct_req.hdrbytes += HTTP1_Write(req->wrk, req->resp, 1);
- if (!req->wantbody)
- req->res_mode &= ~RES_CHUNKED;
-
if (req->res_mode & RES_CHUNKED)
WRW_Chunked(req->wrk);
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index d80c16f..ca15070 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -146,12 +146,10 @@ cnt_deliver(struct worker *wrk, struct req *req)
assert(wrk->handling == VCL_RET_DELIVER);
if (!(req->obj->objcore->flags & OC_F_PASS)
+ && req->esi_level == 0
&& req->obj->response == 200
- && req->http->conds && RFC2616_Do_Cond(req)) {
- req->wantbody = 0;
+ && req->http->conds && RFC2616_Do_Cond(req))
http_SetResp(req->resp, "HTTP/1.1", 304, "Not Modified");
- // http_Unset(req->resp, H_Content_Length);
- }
V1D_Deliver(req);
diff --git a/bin/varnishtest/tests/r01404.vtc b/bin/varnishtest/tests/r01404.vtc
new file mode 100644
index 0000000..1411a00
--- /dev/null
+++ b/bin/varnishtest/tests/r01404.vtc
@@ -0,0 +1,19 @@
+varnishtest "Test that 304 does not send Content-Length"
+
+server s1 {
+ rxreq
+ txresp -hdr "ETag: foo" -body "11111\n"
+} -start
+
+varnish v1 -vcl+backend {
+ sub vcl_backend_response {
+ set beresp.do_stream = true;
+ }
+} -start
+
+client c1 {
+ txreq -hdr "If-None-Match: foo"
+ rxresp -no_obj
+ expect resp.status == 304
+ expect resp.http.Content-Length == <undef>
+} -run
More information about the varnish-commit
mailing list