use strict; use HTTP::Request; use IO::Handle; use HTML::Entities; print "Content-type: text/html\n\n"; print <<"";

print "
";
my $request = HTTP::Request->parse( request_line() . "\n" .
                                    headers() . "\n\n" .
                                    request_body() );

print encode_entities($request->as_string());
print "
"; sub request_line { return sprintf("%s %s %s", $ENV{REQUEST_METHOD}, $ENV{REQUEST_URI}, $ENV{SERVER_PROTOCOL} ); } sub headers { my @header_pair; for my $key ( grep /^HTTP_/, keys %ENV ) { my $field = lc($key); $field =~ s/^http_//; $field =~ tr/_/-/; $field =~ s/\b(\w)/\U\1/g; push @header_pair, join(": ", $field, $ENV{$key}); } return join "\n", @header_pair; } sub request_body { my $body = ""; my $io = IO::Handle->new(); if ($io->fdopen(fileno(STDIN),"r")) { while ( my $line = $io->getline ) { $body .= $line; } $io->close; } return $body; }