Skip to content

Instantly share code, notes, and snippets.

@KristianLyng
Created December 3, 2012 09:55
Show Gist options
  • Select an option

  • Save KristianLyng/4193975 to your computer and use it in GitHub Desktop.

Select an option

Save KristianLyng/4193975 to your computer and use it in GitHub Desktop.
backend betelgeuse {
.host = "178.255.149.146";
.probe = { .url = "/tomfil"; }
}
import digest from "/usr/local/lib/varnish/vmods/libvmod_digest.so";
C{
#include <unistd.h>
}C
sub vcl_recv {
if (req.restarts == 0) {
set req.http.x-orig-url = req.url;
}
//set req.http.host = "kly.no";
if (req.url ~ "^/authfail/") {
error 401;
}
if (req.url ~ "^/retries") {
error 500 "FADGE";
}
if (req.request == "PURGE") {
if (req.url ~ "/auth/") {
if (digest.hmac_sha256("key",req.url + req.http.host + req.http.x-timestamp) != req.http.x-hmac) {
set req.http.x-debug-1 = req.url + req.http.host + req.http.x-timestamp;
set req.http.x-debug-2 = req.http.x-hmac;
error 401 "Steop 1";
}
# if (std.integer("" + now,0) - std.integer(req.http.x-timestamp,0) > 3000) {
# error 401 "Step 2";
# }
}
return (lookup);
}
}
sub vcl_hit {
if (req.request == "PURGE") {
purge;
error 750 "restart";
}
}
sub vcl_miss {
if (req.request == "PURGE") {
purge;
error 750 "restart";
}
}
sub vcl_error {
set obj.http.x-debug-1 = req.http.x-debug-1;
set obj.http.x-debug-2 = req.http.x-debug-2;
if (req.request == "PURGE" && obj.status == 750) {
set req.request = "GET";
set req.url = "/tomfil";
return (restart);
}
}
sub vcl_deliver {
if (req.http.x-orig-url ~ "^/timeout/") {
C{
sleep(10);
}C
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment