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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.