I ran into a frustrating issue today at work. Frustrating because it took me a while to figure out what was going on.
We have an application which runs on mod_perl under a handler called PerlDo. I recently started here so I'm not sure whether PerlDo is a custom handler or released by someone.
Anyway, I was trying to print some arbitrary HTTP headers to communicate with a client application which is not a regular web browser. These headers were something like: "X-error-code"
So inside my "cgi" script (which runs under PerlDo, which in turn runs under mod_perl, so PerlDo seems similar to Apache::Registry), I did this:
print $cgi->header(-X_error_code => 1);
According to the CGI.pm docs, the CGI::header method is supposed to discard the leading dash, turn underscores into dashes, format the header, and return it. So you have to print it.
However, my headers were never sent. In fact, $cgi->header() didn't even return them. I tested a small test script on advice in the chatterbox and it works fine:
perl -MCGI=header -we'print header('-X_error_code' => 1)'
So I dug around in CGI.pm and in the header method I found this code:
if ($MOD_PERL and not $nph) {
$self->r->send_cgi_header($header);
return '';
}
I'm assuming this means CGI.pm wants to think it is smart enough to dispatch the headers instead of just returning them IF it is running under mod_perl. To me, this seems like an extremely silly assumption (pretend I'm using the formatted headers for something else, not just printing them). Furthermore, even if it did want to do that, apparently passing them to the r->send_cgi_header method isn't working regardless.
And it won't return the actual header.
Will someone please explain this behavior? Thanks in advance.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.