-
Notifications
You must be signed in to change notification settings - Fork 728
/
varnish
40 lines (35 loc) · 1.17 KB
/
varnish
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Define a function that converts a string to lower-case in-place.
C{
#include <ctype.h>
static void strtolower(char *c) {
for (; *c; c++) {
if (isupper(*c)) {
*c = tolower(*c);
}
}
}
}C
sub vcl_recv {
if (req.http.host ~ "[A-Z]" || req.url ~ "[A-Z]") {
# Convert host and path to lowercase in-place (dummy C code from Varnish 3 instead of builtin std.tolower function)
C{
/* foo */
strtolower(VRT_GetHdr(sp, HDR_REQ, "\005host:"));
strtolower((char *)VRT_r_req_url(sp));
}C
# and redirect based on the fake HTTP code 701 and set new URL as reason
return (synth(701, "http://" + req.http.host + req.url));
}
# Fall-through to default
}
sub vcl_synth {
# Check for redirects - redirects are performed using: synth(701, "http://target-url/")
# Thus we piggyback the redirect target in the error response variable.
if (701 == resp.status) {
set resp.http.location = resp.reason;
set resp.status = 301;
set resp.reason = "Moved permanently";
return(deliver);
}
# Fall-through to default
}