cgi.pl 1.7 KB

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