Skip to content

Instantly share code, notes, and snippets.

@sdwvit
Created April 10, 2018 00:59
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 sdwvit/b271f1042bff5e7f68e6de7a57ff4f6a to your computer and use it in GitHub Desktop.
Save sdwvit/b271f1042bff5e7f68e6de7a57ff4f6a to your computer and use it in GitHub Desktop.
Signing google static maps URL with fastly
sub vcl_recv {
# Creates google static maps API signature and adds it as one of the query params on the fly. Basically signs URL.
# Key is here: https://consers.google.com/apis/api/static-maps-backend.googleapis.com/ole.developstaticmap/ your_project
set req.http.signature = digest.hmac_sha1_base64(digest.base64_decode("YOUR_KEY"), req.url);
# Create safe-for-web version of the key by replacing '+' -> '-', and '\' -> '_'.
set req.http.signature_url_safe = regsuball(regsuball(req.http.signature, "\+", "-"), "\\", "_");
# Add signature query param to the request url
set req.http.signed_url = querystring.add(req.url, "signature", req.http.signature_url_safe);
# Replace originar request URL with signed/decorated one
set req.url = req.http.signed_url;
# cleanup headers that were used as variables
unset req.http.signature;
unset req.http.signature_url_safe;
unset req.http.signed_url;
return(lookup);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment