summaryrefslogtreecommitdiff
path: root/tests/docroot/www/cgi.pl
blob: 3e7ea872ef9ec9e72519b27b8767e7a1248c5276 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env perl

# env
if ($ENV{"QUERY_STRING"} =~ /^env=(\w+)/) {
    print "Status: 200\r\n\r\n$ENV{$1}";
    exit 0;
}

# redirection
if ($ENV{"QUERY_STRING"} eq "internal-redir") {
    print "Location: /indexfile/index.pl/foo\r\n\r\n";
    exit 0;
}

# redirection
if ($ENV{"QUERY_STRING"} eq "external-redir") {
    print "Location: http://www.example.org:2048/\r\n\r\n";
    exit 0;
}

# 404
if ($ENV{"QUERY_STRING"} eq "send404") {
    print "Status: 404\n\nsend404\n";
    exit 0;
}

# X-Sendfile
if ($ENV{"QUERY_STRING"} eq "xsendfile") {
    # urlencode path for CGI header
    # (including urlencode ',' if in path, for X-Sendfile2 w/ FastCGI (not CGI))
    # (This implementation is not minimal encoding;
    #  encode everything that is not alphanumeric, '.' '_', '-', '/')
    require Cwd;
    my $path = Cwd::getcwd() . "/index.txt";
    $path =~ s#([^\w./-])#"%".unpack("H2",$1)#eg;

    print "Status: 200\r\n";
    print "X-Sendfile: $path\r\n\r\n";
    exit 0;
}

# NPH
if ($ENV{"QUERY_STRING"} =~ /^nph=(\w+)/) {
    print "Status: $1 FooBar\r\n\r\n";
    exit 0;
}

# crlfcrash
if ($ENV{"QUERY_STRING"} eq "crlfcrash") {
    print "Location: http://www.example.org/\r\n\n\n";
    exit 0;
}

# POST length
if ($ENV{"QUERY_STRING"} eq "post-len") {
    $cl = $ENV{CONTENT_LENGTH} || 0;
    my $len = 0;
    if ($ENV{"REQUEST_METHOD"} eq "POST") {
        while (<>) { # expect test data to end in newline
            $len += length($_);
            last if $len >= $cl;
        }
    }
    print "Status: 200\r\n\r\n$len";
    exit 0;
}

# default
print "Content-Type: text/plain\r\n\r\n";
print $ENV{"QUERY_STRING"};

0;