Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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: 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment