Hello monks I would expect the direct use of HTTP::Response object in a cgi script to deliver the correct output (headers and content etc) to send back to the calling client (a browser in my case) and to display the contents sent back. This is not happening as on an apache server (that i do not control), I get a internal server error thrown back, yet on a lighttpd server, I get asked to save the returned results. Here is the test code using HTTP::Response
#!/usr/bin/perl use strict; use warnings; use HTTP::Response; my $respbody = '<root/>'; my $response; $response = HTTP::Response->new('200','Ok'); $response->header( 'Content-type' => 'application/xml' ); $response->header( 'Cache-control' => 'no-cache, must-revalidate' ); $response->header( 'Content-length' => length($respbody) ); $response->content($respbody); print $response->as_string; 1; __END__
result in headers trace as follows
http://localhost/tia/signage/edit/myresp.pl GET /tia/signage/edit/myresp.pl HTTP/1.1 Host: localhost User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Firef +ox/45.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0. +8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive HTTP/1.1 200 OK Content-Length: 105 Date: Sun, 08 Jan 2017 23:08:16 GMT Server: lighttpd
and the actual content (re: using lighttpd)
200 OK Cache-Control: no-cache, must-revalidate Content-Length: 7 Content-Type: application/xml <root/>
If I use print statements as in the following, all is ok.
#!/usr/bin/perl use strict; use warnings; print "Status: 200\n"; print "Content-Type: application/xml\n\n"; print "<root/>\n"; 1; __END__
It appears to me that the HTTP:Response object, when using method '->as_string', does not send [at least] the correct formatted status line. Can the HTTP::Response object be used directly in a server cgi script and if so, how should I use it to get it to work as expected... in this test case, to show the simple xml in the browser (which it does if I use just the print statements as shown).

Thank you for any insight.
Habs

PS: sorry for any post formatting irregularities - I struggle !

In reply to using HTTP::Response directly by Habs

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.