-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cache_req_fsm: keep the cache object's Content-Length for HEAD always
Previously, we would only keep the Content-Length header for HEAD requests on hit-for-miss objects, now we simply keep it always to enable "fallback" caching of HEAD requests. The added vtc implements the basics of the logic to enable the (reasonable) use case documented in #2107 (comment) but using Vary instead of cache key modification plus restart. Fixes #4245
- Loading branch information
Showing
2 changed files
with
79 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
varnishtest "cache a HEAD as a fallback for a GET" | ||
|
||
server s1 { | ||
rxreq | ||
expect req.method == "HEAD" | ||
expect req.http.t == "headmiss" | ||
txresp -nolen -hdr "Content-Length: 42" | ||
|
||
rxreq | ||
expect req.method == "GET" | ||
expect req.http.t == "getmiss" | ||
txresp -bodylen 42 | ||
} -start | ||
|
||
varnish v1 -vcl+backend { | ||
sub vcl_recv { | ||
if (req.method == "HEAD") { | ||
set req.http.X-Fetch-Method = "HEAD"; | ||
} else { | ||
unset req.http.X-Fetch-Method; | ||
} | ||
} | ||
|
||
sub vcl_backend_fetch { | ||
if (bereq.http.X-Fetch-Method) { | ||
set bereq.method = bereq.http.X-Fetch-Method; | ||
} | ||
} | ||
|
||
sub vcl_backend_response { | ||
# NOTE: this use of Vary is specific to this case, it is | ||
# usually WRONG to only set Vary for a specific condition | ||
if (bereq.http.X-Fetch-Method) { | ||
if (beresp.http.Vary) { | ||
set beresp.http.Vary += ", X-Fetch-Method"; | ||
} else { | ||
set beresp.http.Vary = "X-Fetch-Method"; | ||
} | ||
} | ||
set beresp.http.t = bereq.http.t; | ||
} | ||
|
||
sub vcl_deliver { | ||
# Vary cleanup | ||
if (resp.http.Vary == "X-Fetch-Method") { | ||
unset resp.http.Vary; | ||
} else if (resp.http.Vary ~ ", X-Fetch-Method$") { | ||
set resp.http.Vary = | ||
regsub(resp.http.Vary, ", X-Fetch-Method$", ""); | ||
} | ||
} | ||
} -start | ||
|
||
client c1 { | ||
# miss | ||
txreq -method "HEAD" -hdr "t: headmiss" | ||
rxresphdrs | ||
expect resp.http.t == "headmiss" | ||
# hit | ||
txreq -method "HEAD" -hdr "t: headhit" | ||
rxresphdrs | ||
expect resp.http.t == "headmiss" | ||
|
||
# miss | ||
txreq -hdr "t: getmiss" | ||
rxresp | ||
expect resp.http.t == "getmiss" | ||
# hits on full object | ||
txreq -hdr "t: gethit" | ||
rxresp | ||
expect resp.http.t == "getmiss" | ||
txreq -method "HEAD" -hdr "t: getheadhit" | ||
rxresphdrs | ||
expect resp.http.t == "getmiss" | ||
} -run | ||
|
||
server s1 -wait |