Created
August 11, 2009 17:28
-
-
Save eik3/165978 to your computer and use it in GitHub Desktop.
Varnish VCL to randomize an URL
This file contains 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
# C includes must happen outside a VCL function | |
# see http://varnish-cache.org/wiki/VCLExampleSyslog | |
C{ | |
#include <stdlib.h> | |
#include <time.h> | |
#include <stdio.h> | |
}C | |
sub vcl_recv { | |
if (req.url ~ "^/random$" ) { | |
C{ | |
#define MINVAL 1 | |
#define MAXVAL 100 | |
#define BASEURL "/random/" | |
srand((double)time(NULL)); | |
int r=MINVAL+(rand()%MAXVAL); | |
char s[50]; | |
sprintf(s, BASEURL"%i", r); | |
VRT_l_req_url(sp, s, vrt_magic_string_end); | |
}C | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment