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