Created
April 10, 2018 00:59
-
-
Save sdwvit/b271f1042bff5e7f68e6de7a57ff4f6a to your computer and use it in GitHub Desktop.
Signing google static maps URL with fastly
This file contains 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
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