Skip to content

Instantly share code, notes, and snippets.

@rezan
Created March 30, 2021 13:23
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/dbc5dfc339453fdcf7ee5f3e989d127c to your computer and use it in GitHub Desktop.
Save rezan/dbc5dfc339453fdcf7ee5f3e989d127c to your computer and use it in GitHub Desktop.
VHA6 req.url rewrite hook
#
# VHA6 req.url rewrite hook
#
# File location: /etc/varnish/vha6/hooks/states.vcl
#
import std;
sub vha6_hook_init {
}
sub vha6_hook_broadcast {
vha.log("HOOK BROADCAST SWAP");
# Swap out the hash for the url
http.req_set_url(9,
vha6_opts.get("broadcaster_scheme", "http") + "://" +
vha6_opts.get("broadcaster_host", "localhost") + ":" +
vha6_opts.get("broadcaster_port", "8088") +
bereq.url);
http.req_set_header(9, "vha6-hash", blob.encode(HEX, LOWER, bereq.hash));
}
sub vha6_hook_peer_recv {
vha.log("HOOK PEER RECV SWAP");
# Swap back in the hash
if (!req.http.vha6-hash) {
return (synth(500, "HASH SWAP FAIL"));
}
set req.url = "/" + req.http.vha6-hash;
}
sub vha6_hook_peer_fetch {
}
sub vha6_hook_origin_recv {
}
sub vha6_hook_origin_deliver {
}
sub vha6_hook_peer_insert {
}
# EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment