Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Header problem with IIS, C::A and CGI::Simple

by meraxes (Friar)
on Aug 19, 2005 at 03:05 UTC ( #485009=perlquestion: print w/replies, xml ) Need Help??
meraxes has asked for the wisdom of the Perl Monks concerning the following question:

Hello esteemed monks,

I'm writing my first CGI::Application web app and I'm having some growing pains for which I was hoping someone could help. It works great on my Apache test setup on my own work box. It blows chunks when I try to use it on the IIS5 box on which my boss wants me to put it.

The problem is similar to this: How can I remove HTTP Header . I have headers in a single line printing out along the top of my page... however, unlike the aforementioned node, this isn't happening all the time. From what I can see, it's only happening when I POST a form or attempt to redirect.

This webapp was developed on my WinXP box using Apache 2.0 as my test webserver and Perl 5.8.6. It uses CGI::Application (C::A) but I've overridden it to use CGI::Simple instead of CGI as per this tip in the C::A Wiki like so:

sub cgiapp_get_query { my $self = shift; require CGI::Simple; my $q = CGI::Simple->new(); return $q; }

Unfortunately, I've gotta move this bad-boy to a Win2k box running IIS5 (also Perl 5.8.6). It's not using the ISAPI plugin for Perl. (Is that a factor?)

I'm aware of the nph header setting and I'm setting the CGI::Simple query object to nph like so in the setup() method (even though the docs say that I need not do so because CGI::Simple auto-detects IIS):


I'm doing redirects in my run_modes just like the C::A documentation tells me like this:

$self->header_type('redirect'); $self->header_props( -url => $newurl ); return;

The redirects in Firefox and IE are both causing a download of the redirect headers as a text file instead of actually redirecting me. The form submission is also causing a download in FireFox but in IE I get a printout of the headers at the top of the page in one line like so:

HTTP/1.0 200 OK Server: Microsoft-IIS/5.0 Date: Fri, 19 Aug 2005 02:42 +:29 GMT Content-Type: text/html; charset=ISO-8859-1

Sorry if this seemed a little long winded but I'm trying to provide as much as possible. So, I understand the concept of NPH... what I don't get is how this beahviour seems to be busting me up only some times and not all the time. (Can't ANYTHING be black and white anymore? Hmmm... I must be growing up if everything is in shades of gray.)

Has anyone else had this selective behaviour? Do I need to explicitly set some more headers somewhere? Is this something to do with CGI::Simple's NPH support? All help is welcome and if anyone want's more detail, I'll give it. None of the other nodes I've come across here seem to cover this. All I'm looking for now is a direction to investigate in because I'm plain stumped. My apologies if this is isn't "perlish" enough but I'm not sure where else to turn.

Many Thanks,

Update: Okay, I've got redirects working. It seems that when I was using the header_props() to set the type to redirect I think I was wiping out the -nph setting. I've corrected this. However, I still have a problem when I process a POST request. The result page is still spitting out the headers. The output page is using no special headers at all. Any help appreciated.

Update the second: I'm an idiot. hakkr got me looking in the right direction. I'm not printing out headers ahead of CGI::Application... but I was printing some diagnositic info to STDERR. Apache throws that into it's erorr log, IIS just spews EVERYTHING out. Many thanks for the help.

Replies are listed 'Best First'.
Re: Header problem with IIS, C::A and CGI::Simple
by hakkr (Chaplain) on Aug 19, 2005 at 08:25 UTC
    When you are attempting the redirect you need to set the nph flag.
    print $query->redirect(-uri=>‚http://somewhere.else/in/movie/land‚,-n +ph=>1);
    from man CGI

    The -nph parameter, if set to a true value, will issue the correct headers to work with a NPH (no-parse-header) script. This is important to use with certain servers, such as Microsoft Internet Explorer, which expect all their scripts to be NPH.

    You can pass nph=>1 using the CGI::Application
    header_props(-uri=>'' , -nph=>1)
    Update - if the results page is showing the header, you are most likely printing the header out twice. Note CGI::Application usually prints headers for you

      Doesn't the line:


      Do this for me? The docs say that "You can set NPH mode in any of the following ways:" including the above. If I'm having NPH problems, would I be having this problem with all pages, not just redirects and POSTS?

      Update: I'm not directly printing out any headers. Only using header_props() and header_add(). In the result runmode I'm not even modifying any headers at all. That's why I'm so baffled.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://485009]
Approved by Roger
Front-paged by planetscape
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2018-04-24 19:02 GMT
Find Nodes?
    Voting Booth?