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

What is the Scope of Bean object with BeanUtils.populate() Method?

jsp servlets apache-commons-beanutils

i previously used <jsp:useBean> tags that have facility to decide the scope of bean for page or request or session or application but now i moved to MVC architechture, where i am using BeanUt...

iPython Notebook Markdown Programability for Base Directory

markdown ipython-notebook

I have an iPython notebook with many links to a sharepoint file set within markdown. It is likely that the base location of the files will change at some point in the future. Ideally, I could

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.