Last active
December 2, 2019 23:00
-
-
Save rezan/38cf0d17dad9fe7a3e144c62a055f221 to your computer and use it in GitHub Desktop.
Varnish VCL JSON support (test)
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 "JSONP support" | |
server s1 -repeat 2 { | |
rxreq | |
txresp -hdr "Content-Type: application/json" -body {"json"} | |
} -start | |
varnish v1 -vcl+backend { | |
import urlplus; | |
import xbody; | |
sub vcl_backend_response { | |
# Insert the JSONP callback | |
if (urlplus.query_get("callback") && beresp.http.Content-Type ~ "json") { | |
xbody.regsub("^", urlplus.query_get("callback") + "("); | |
xbody.regsub("$", ");"); | |
set beresp.http.Content-Type = regsub(beresp.http.Content-Type, "json", "javascript"); | |
} | |
} | |
} -start | |
client c1 { | |
txreq -url /1 | |
rxresp | |
expect resp.status == 200 | |
expect resp.body == {"json"} | |
expect resp.http.Content-Type ~ "json" | |
txreq -url /1?callback=my_func | |
rxresp | |
expect resp.status == 200 | |
expect resp.body == {my_func("json");} | |
expect resp.http.Content-Type ~ "javascript" | |
} -run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment