1#!/usr/bin/env perl 2 3# env 4if ($ENV{"QUERY_STRING"} =~ /^env=(\w+)/) { 5 my $v = defined($ENV{$1}) ? $ENV{$1} : "[$1 not found]"; 6 print "Status: 200\r\n\r\n$v"; 7 exit 0; 8} 9 10# redirection 11if ($ENV{"QUERY_STRING"} eq "internal-redir") { 12 # (not actually 404 error, but use separate script from cgi.pl for testing) 13 print "Location: /404.pl/internal-redir\r\n\r\n"; 14 exit 0; 15} 16 17# redirection 18if ($ENV{"QUERY_STRING"} eq "external-redir") { 19 print "Location: http://www.example.org:2048/\r\n\r\n"; 20 exit 0; 21} 22 23# 404 24if ($ENV{"QUERY_STRING"} eq "send404") { 25 print "Status: 404\n\nsend404\n"; 26 exit 0; 27} 28 29# X-Sendfile 30if ($ENV{"QUERY_STRING"} eq "xsendfile") { 31 # urlencode path for CGI header 32 # (including urlencode ',' if in path, for X-Sendfile2 w/ FastCGI (not CGI)) 33 # (This implementation is not minimal encoding; 34 # encode everything that is not alphanumeric, '.' '_', '-', '/') 35 require Cwd; 36 my $path = Cwd::getcwd() . "/index.txt"; 37 $path =~ s#([^\w./-])#"%".unpack("H2",$1)#eg; 38 39 print "Status: 200\r\n"; 40 print "X-Sendfile: $path\r\n\r\n"; 41 exit 0; 42} 43 44# NPH 45if ($ENV{"QUERY_STRING"} =~ /^nph=(\w+)/) { 46 print "Status: $1 FooBar\r\n\r\n"; 47 exit 0; 48} 49 50# crlfcrash 51if ($ENV{"QUERY_STRING"} eq "crlfcrash") { 52 print "Location: http://www.example.org/\r\n\n\n"; 53 exit 0; 54} 55 56# POST length 57if ($ENV{"QUERY_STRING"} eq "post-len") { 58 $cl = $ENV{CONTENT_LENGTH} || 0; 59 my $len = 0; 60 if ($ENV{"REQUEST_METHOD"} eq "POST") { 61 while (<>) { # expect test data to end in newline 62 $len += length($_); 63 last if $len >= $cl; 64 } 65 } 66 print "Status: 200\r\n\r\n$len"; 67 exit 0; 68} 69 70# default 71print "Content-Type: text/plain\r\n\r\n"; 72print $ENV{"QUERY_STRING"}; 73 740; 75