Actually, this is the time to ask for best (better?) practices. I have some test code, below, that does what I want (under limited/broken circumstances; not mod_perl, etc). Reconstitutes an HTTP::Request. Anyone want to look at the functionality and tell me how I should really be doing it and with which modules?
use strict; use HTTP::Request; use IO::Handle; use HTML::Entities; print "Content-type: text/html\n\n"; print <<""; <form method="post" action="/http-request.pl" enctype="multipart/form-data"> <input name="form_field" /> <input type="submit" name="Submit!" /> </form><hr /> print "<pre>"; my $request = HTTP::Request->parse( request_line() . "\n" . headers() . "\n\n" . request_body() ); print encode_entities($request->as_string()); print "</pre>"; 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; }
In reply to Re: Read a raw POST request, as is
by Anonymous Monk
in thread Read a raw POST request, as is
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |