Skip to content

Commit f355ba3

Browse files
committed
cache_fetch: Send Content-Length: 0 for POST, PUT and PATCH
otherwise keep the existing logic of sending no Content-Length header if there is no request body. This code runs before vcl_backend_fetch, so should VCL gain back control over Content-Length as proposed in #4331, it will be possible again to override this default. Fixes #4331 for the special case
1 parent 36fad69 commit f355ba3

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

bin/varnishd/cache/cache_fetch.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,15 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
411411

412412
http_PrintfHeader(bo->bereq, "X-Varnish: %ju", VXID(bo->vsl->wid));
413413

414-
if (bo->bereq_body == NULL && bo->req == NULL)
415-
http_Unset(bo->bereq, H_Content_Length);
414+
if (bo->bereq_body == NULL && bo->req == NULL) {
415+
const char *met = http_GetMethod(bo->bereq);
416+
if (http_method_eq(met, POST) ||
417+
http_method_eq(met, PUT) ||
418+
http_method_eq(met, PATCH))
419+
http_ForceHeader(bo->bereq, H_Content_Length, "0");
420+
else
421+
http_Unset(bo->bereq, H_Content_Length);
422+
}
416423

417424
VCL_backend_fetch_method(bo->vcl, wrk, NULL, bo, NULL);
418425

bin/varnishtest/tests/r04331.vtc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
varnishtest "C-L with empty POST"
2+
3+
server s1 {
4+
rxreq
5+
txresp
6+
expect req.http.content-length == 0
7+
} -start
8+
9+
varnish v1 -vcl+backend {
10+
11+
} -start
12+
13+
client c1 {
14+
txreq -method POST -hdr "content-length: 0"
15+
rxresp
16+
} -run
17+
18+
server s1 -wait

0 commit comments

Comments
 (0)