Created
March 30, 2021 13:23
-
-
Save rezan/dbc5dfc339453fdcf7ee5f3e989d127c to your computer and use it in GitHub Desktop.
VHA6 req.url rewrite hook
This file contains hidden or 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
# | |
# 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