You can. Just take care of that you have to output CGI headers, not http headers. This means in practice that you do not have to print a http status line (the one with a three-digit number), instead the webserver will print one as approperiate (200 normally, 302 in case you print a Location header so the server thinks it's a redirect), and that the server will correct the line endings of your header to crlfs. (Update: the server will also do the chunked encoding if you don't specify the Content-length, do the keepalive connection, and lots of other magical stuff I can't even imagine.)

The only header you are required to print is Content-type. Just search perlmonks for "Content-type", and you'll find lots of examples. (In case you wanted to write http requests by hand, you can do that too: in that case the only required header is Host.)

Update: it seems I didn't answer your question. Well, the CGI module does not output any headers, so it is safe to use it just the input part.


In reply to Re: Should I just print my own HTTP headers? by ambrus
in thread Should I just print my own HTTP headers? by Cap'n Steve

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.