I see it prints HTTP headers with the status line first. So I changed the handler to work around that. I capture the output that has been written through CGI STDOUT, then mangle the headers and print that.

sub handler { capture { MyModule->new->go; } \$out; my ($header, $body) = split /\r\n\r\n/, $out, 2; my $h = HTTP::Headers->new; for my $line (split /\r\n/, $header) { my ($key, $value) = split /: /, $line, 2; $h->header($key, $value); } $h->header('Status' => 200) unless $h->header('Status'); my $status = $h->header('Status'); $h->remove_header('Status'); print 'HTTP/1.1 ' . HTTP::Response->new($status => undef, $h, $body)->as_string("\ +r\n"); }

Now the tests pass, except the last one! That's the one about POST data. Thus:

is $r->content, $post_data; # Failed test at foobar.t line 85. # got: '' # expected: 'some post data' # Looks like you failed 1 test of 8.
diag $r->as_string shows:
# HTTP/1.1 201 Created # Location: http://localhost:12345 # Content-Type: text/html; charset=ISO-8859-1 # Client-Aborted: die # Client-Date: Tue, 17 Feb 2009 18:16:12 GMT # Client-Response-Num: 1 # X-Died: read failed: Connection reset by peer at .../LWP/Protocol/ht +tp.pm line 382, <DATA> line 16. #

Note that the transmitted HTTP body disappeared. I can confirm that it does not arrive anymore by the time CGI is initialised. I can confirm that the capturing causes that.

What do I do now?


In reply to Re^2: problems with HTTP::Server::Simple::CGI by Anonymous Monk
in thread problems with HTTP::Server::Simple::CGI 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.