How can I get a header that will work with IIS 6, 7 and Apache?

I am trying to get a header that will work with Apache, IIS 6 and IIS 7. I will not go into the reason for this. Let's just say it's not as easy as I thought it would be :-)

Anyway, the problem has something to do with NPH. In our code (originally written for IIS 6) we have

use CGI qw(:standard);

print "HTTP/1.0 200 OK\n";

print header;

      

at the top of each cgi script; I read that this is how you tell IIS that you want NPH.

Apache uses the filename to see if the output is nph (nph- should be the start of the filename), so I did (which works in both IIS 6 and Apache):

use CGI qw(:standard);
print header('text/html', '200 OK');

      

IIS 7, I wonder, seems to require NPH, so if I don't

use CGI qw(:standard -nph);

      

or

print "HTTP/1.0 200 OK\n";

print header('text/html', '200 OK'); #parameters are apparently optional 

      

the browser is trying to do something weird with the file as it doesn't get the mimetype.

Also note, IIS 6 and 7 are fine without printing any headers, but Apache doesn't like that.

Anyway, the best thing to do now is

use CGI qw(:standard);
print header('text/html', '200 OK');

      

somehow works in IIS 7. Does anyone know how I can do this? I don't know all the details of our server configuration, but if you can tell me how to get any details you might need, I can do it.

Thank you anyway!

+1


source to share


2 answers


Brian (and others) told me to write a subroutine that would do the right thing. Hope this helps someone else!
sub header {
    return (($ENV{PERLXS})?"HTTP/1.0 200 OK\r\n":"").CGI->header(@_);
}

      



0


source


I would just create a routine that does the right thing depending on the server. You know what you need to do in each case, so just do it in that case.

Another option is to fix the CGI.pm to set the $ CGI :: NPH variable correctly by looking at the server type. CGI.pm already has the basics. Once you fix this, submit the patch.



Good luck :)

+1


source







All Articles