Created
March 20, 2020 20:41
-
-
Save rezan/d49cc61c5ff70dfd89f47ff08fccfe2c to your computer and use it in GitHub Desktop.
Generate an ETag with xbody
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 "Use xbody to generate an Etag" | |
server s1 { | |
rxreq | |
txresp -body "This is a test" | |
} -start | |
varnish v1 -vcl+backend { | |
import crypto; | |
import xbody; | |
sub vcl_backend_response { | |
xbody.regsub("test", "cat"); | |
xbody.hash_body(sha1); | |
} | |
sub vcl_deliver { | |
set resp.http.ETag = {"""} + crypto.hex_encode(xbody.get_hash()) + {"""}; | |
} | |
} -start | |
client c1 { | |
txreq | |
rxresp | |
expect resp.status == 200 | |
expect resp.http.ETag == {"2630a8082bcee40c4a9b341ac30c325378428c21"} | |
expect resp.body == "This is a cat" | |
txreq -hdr {If-None-Match: "2630a8082bcee40c4a9b341ac30c325378428c21"} | |
rxresp | |
expect resp.status == 304 | |
expect resp.bodylen == 0 | |
} -run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment