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 won't go into the reason for that here. Let's just say that 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 every 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- must be the beginning of the filename) so what I did (which works in both IIS 6 and Apache) is the following:

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

IIS 7, interestingly, seems to require NPH, so if I don't either do

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 tries to do something weird with the file, since it doesn't get the mimetype.

Also note: IIS 6 and 7 are ok without printing any header at all, but Apache doesn't like that.

Anyway, the best thing right now would be to make

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

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

Thanks either way!

Answers


I'd just create a subroutine that does the right thing depending on the server. You know what you have to do in each case, so just do that in that case.

The other option is to patch CGI.pm to set its $CGI::NPH variable correctly by looking at the server type. CGI.pm already has the basics there. Once you fix that, submit a patch.

Good luck :)


Need Your Help

Working with multiple branches in ASP .NET

asp.net iis virtual branch directory

I've seen several other posts similar to this (namely https://stackoverflow.com/questions/5237/solutions-for-working-with-multiple-branches-in-asp-net) but there are several issues that I have that...

How to display signature in macro used for sending mail from outlook?

excel vba excel-vba outlook

Currently I have created a macro which have some content as Body and after that I want to show default signature of outlook user .