Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I need to explicitly output the HTTP header for IIS but not Apache?

I am trying to set up apache instead of IIS because IIS needlessly crashes all the time, and it would be nice to be able to have my own checkout of the source instead of all of us editing a common checkout.

In IIS we must do something like this at the beginning of each file:

use CGI;
my $input = new CGI();
print "HTTP/1.0 200 OK";
print $input->header();

whereas with apache we must leave off the 200 OK line. The following works with both:

use CGI;
my $input = new CGI();
print $input->header('text/html','200 OK');

Can anyone explain why? And I was under the impression that the CGI module was supposed to figure out these kind of details automatically...

Thanks!

Update: brian is right, nph fixes the problem for IIS, but it is still broken for Apache. I don't think it's worth it to have conditionals all over the code so I will just stick with the last method, which works with and without nph.

like image 862
Frew Schmidt Avatar asked Nov 21 '08 06:11

Frew Schmidt


People also ask

What is HTTP response header in IIS?

Overview. The <customHeaders> element of the <httpProtocol> element specifies custom HTTP headers that Internet Information Services (IIS) 7 will return in HTTP responses from the Web server. HTTP headers are name and value pairs that are returned in responses from a Web server.

Where is HTTP headers in IIS?

Add custom HTTP response header in IIS 7.0 In the connections pane, expand the node for the server, and then expand Sites. Select the web site where you want to add the custom HTTP response header. In the web site pane, double-click HTTP Response Headers in the IIS section. In the actions pane, select Add.

What is the HTTP response header?

A response header is an HTTP header that can be used in an HTTP response and that doesn't relate to the content of the message. Response headers, like Age , Location or Server are used to give a more detailed context of the response.

What are HTTP headers stack overflow?

HTTP headers allow a client and server to understand each other better, meaning they can communicate more effectively. Tells the server about the client's setup (browser, OS etc.)


1 Answers

HTTP and CGI are different things. The Perl CGI module calls what it does an "HTTP header", but it's really just a CGI header for the server to fix up before it goes back to the client. They look a lot alike which is why people get confused and why the CGI.pm docs don't help by calling them the wrong thing.

Apache fixes up the CGI headers to make them into HTTP headers, including adding the HTTP status line and anything else it might need.

If you webserver isn't fixing up the header for you, it's probably expecting a "no-parsed header" where you take responsibility for the entire header. To do that in CGI.pm, you have to add the -nph option to your call to header, and you have to make the complete header yourself, including headers such as Expires and Last-Modified. See the docs under Creating a Standard HTTP Header. You can turn on NPH in three ways:

use CGI qw(-nph)

CGI::nph(1)

print header( -nph => 1, ...)

Are you using an older version of IIS? CGI.pm used to turn on the NPH feature for you automatically for IIS, but now that line is commented out in the source in CGI.pm:

# This no longer seems to be necessary
# Turn on NPH scripts by default when running under IIS server!
# $NPH++ if defined($ENV{'SERVER_SOFTWARE'}) && $ENV{'SERVER_SOFTWARE'}=~/IIS/;
like image 86
brian d foy Avatar answered Sep 18 '22 21:09

brian d foy