Created
April 1, 2019 13:35
-
-
Save rezan/eed6684c4456617544305053b4e08da5 to your computer and use it in GitHub Desktop.
Resp body hashing 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 "Resp body hashing" | |
server s1 { | |
rxreq | |
txresp -body "ABC 123" | |
expect req.url == "/1" | |
rxreq | |
txresp -body "test!" | |
expect req.url == "/2" | |
rxreq | |
txresp -nolen -hdr "Transfer-encoding: chunked" | |
chunked {AB} | |
chunked {C 1} | |
chunked {2} | |
chunked {3} | |
chunkedlen 0 | |
expect req.url == "/3" | |
} -start | |
varnish v1 -vcl+backend { | |
import crypto; | |
import xbody; | |
sub vcl_backend_response | |
{ | |
xbody.capture("body", "^([\s\S]*)$", "\1"); | |
} | |
sub vcl_deliver | |
{ | |
set resp.http.body-hash = crypto.hex_encode(crypto.hash(sha1, xbody.get("body"))); | |
} | |
} -start | |
client c1 { | |
txreq -url /1 | |
rxresp | |
expect resp.status == 200 | |
expect resp.body == "ABC 123" | |
expect resp.http.body-hash == "0d96c730d25424679aa751cf1c3c019dd5001c1e" | |
txreq -url /2 | |
rxresp | |
expect resp.status == 200 | |
expect resp.body == "test!" | |
expect resp.http.body-hash == "b7c0a3d1c11afbb20e06aa13404c57be37c5cdeb" | |
txreq -url /3 | |
rxresp | |
expect resp.status == 200 | |
expect resp.body == "ABC 123" | |
expect resp.http.body-hash == "0d96c730d25424679aa751cf1c3c019dd5001c1e" | |
} -run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment