Skip to content

Instantly share code, notes, and snippets.

@rezan
Last active December 2, 2019 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rezan/4a3f34b703ae8c026a21fc1624489062 to your computer and use it in GitHub Desktop.
Save rezan/4a3f34b703ae8c026a21fc1624489062 to your computer and use it in GitHub Desktop.
Varnish VCL JSONP support
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