Skip to content

Instantly share code, notes, and snippets.

@eik3
Created August 11, 2009 17:28
Show Gist options
  • Save eik3/165978 to your computer and use it in GitHub Desktop.
Save eik3/165978 to your computer and use it in GitHub Desktop.
Varnish VCL to randomize an URL
# 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