Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Malformed header from script. Bad header=HTTP/1.1 302 Found

Tags:

http

cgi

I have a C++ program acting as a CGI script, and I am currently using Cgicc to do some of the parsing and formatting for me (though it will probably be replaced at some point). When constructing my response, I use cgicc::HttpResponseHeader, which will create me something like

HTTP/1.1 302 Found
Location: www.bla.com

This looks pretty standard to me. However, the Webserver chokes on that, giving me a

<...> malformed header from script. Bad header=HTTP/1.1 302 Found: script.cgi

I found out how to fix this:

  1. Remove the HTTP/... line
  2. Add instead a line Status: 302 Found

And in fact, that is exactly what cgicc::HttpRedirectHeader does. I have now two questions:

  1. Is this line HTTP/1.1 302 Found not standard?
  2. If it isn't, why is cgicc::HttpResponseHeader doing that? If it is, why does my webserver choke on it?

Note I am not looking for ways to get around this, I know how to do that. I just want to understand whats going on.

Cheers Ole

like image 201
Ole Avatar asked Jun 27 '12 09:06

Ole


1 Answers

The HTTP line is standard HTTP, but not standard CGI.

Under CGI, the script uses a Status header to communicate the status back to the web server, and the web server constructs the HTTP response line from that status code.

Why cgicc is constructing the HTTP line I don't know - is it possible that you're not supposed to use that particular class in that context? Perhaps that class is only for use with nph scripts? The documentation does kind of imply that - after describing the set of standard response classes, it says:

cgicc::HTTPResponseHeader is a more powerful, generic HTTP header class used to construct a full HTTP response.

The implication is that it's unusual to use that in a normal CGI script.

like image 195
RichieHindle Avatar answered Sep 18 '22 06:09

RichieHindle