Last active
December 2, 2019 23:00
-
-
Save rezan/4a3f34b703ae8c026a21fc1624489062 to your computer and use it in GitHub Desktop.
Varnish VCL JSONP support
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
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"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment