File: vcl

package info (click to toggle)
ruby-rouge 4.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,836 kB
  • sloc: ruby: 38,168; sed: 2,071; perl: 152; makefile: 8
file content (61 lines) | stat: -rw-r--r-- 1,689 bytes parent folder | download | duplicates (4)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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
}

#### Fastly's dialect ####

# reference: https://docs.fastly.com/vcl/

# local variables
declare local var.ip1 IP;
set var.ip1 = "192.0.2.0";

# string literals
set var.s = {xyz"Hello, world!"xyz}; # heredoc-style

# more literals
set resp.http.X-Str = {"Hello, world!"};
set resp.http.X-Rtime = 10ms;
set resp.http.X-RTime = 2.5h;
set resp.http.X-Int = 0xFF;
set resp.http.X-Float = 1.2e3;
set resp.http.X-Float = 1e2;
set resp.http.X-HexFloat = 0xA.Bp3;
set resp.http.X-HexFloat = 0xAp3;