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