Created
February 20, 2017 20:56
-
-
Save rezan/7cb5ad0cf5ff1683e8bb7c5bb842b566 to your computer and use it in GitHub Desktop.
Cache POST requests
This file contains hidden or 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
varnishtest "Cache POSTs" | |
server s1 { | |
rxreq | |
txresp -body "resp_body" | |
expect req.url == "/" | |
expect req.method == "POST" | |
expect req.bodylen == 14 | |
} -start | |
varnish v1 -vcl+backend { | |
import std; | |
import bodyaccess; | |
sub vcl_recv { | |
std.cache_req_body(1KB); | |
set req.http.X-len = bodyaccess.len_req_body(); | |
if (req.method == "POST") { | |
set req.http.X-method = req.method; | |
return(hash); | |
} | |
} | |
sub vcl_backend_fetch { | |
if (bereq.http.X-method) { | |
set bereq.method = bereq.http.X-method; | |
} | |
} | |
sub vcl_hash { | |
bodyaccess.hash_req_body(); | |
} | |
sub vcl_deliver { | |
set resp.http.X-len = req.http.X-len; | |
set resp.http.X-hits = obj.hits; | |
} | |
} -start | |
client c1 { | |
txreq -req "POST" -url "/" -body "post_body_here" | |
rxresp | |
expect resp.status == 200 | |
expect resp.body == "resp_body" | |
expect resp.http.X-len == 14 | |
expect resp.http.X-hits == 0 | |
txreq -req "POST" -url "/" -body "post_body_here" | |
rxresp | |
expect resp.status == 200 | |
expect resp.body == "resp_body" | |
expect resp.http.X-len == 14 | |
expect resp.http.X-hits == 1 | |
} -run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment