Forum Moderators: phranque
I met a "Request failed: error reading the headers" during using script to check the apache sanity in Linux. It works fine on Solaris, but always get a 400 bad request response on Linux. Maybe there is some one met the same problem, or can help me to solve it.
Apache version is 2.2.13. I use a script to check if the Apache still running. The statements is like:
echo "GET /ahe/cgi-bin/webcheck HTTP/1.0\n" ¦ /usr/bin/telnet 127.0.0.1 80¦grep "200 OK"¦read INPUT
And then use the "exit $?" to judge if Apache's runing ok. Here the /ahe/cgi-bin/webcheck is a simple cgi. This works fine on Solaris. But after I compiled Apache 2.2.13 and installed it on Linux, problem occurred.
In Apache error log, always got:
[Thu Nov 19 03:42:15 2009] [error] [client 127.0.0.1] request failed: error reading the headers
And the corresponding access log message is:
127.0.0.1 - - [19/Nov/2009:03:42:16 -0600] "GET /ahe/cgi-bin/webcheck HTTP/1.0\\n" 400 226 "-" "-"
You see Apache think this is a bad request and return a 440 response. But when I access this webcheck cgi from IE, it works fine. In Apache access log, for IE accessing is like,
135.252.158.178 - - [19/Nov/2009:10:33:48 -0600] "GET /ahe/cgi-bin/webcheck HTTP/1.1" 200 15 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)"
Is there some items in httpd.conf I should change? I changed the LimitRequestFieldSize, but doesn't work.
And also I noticed that in Apache access log in Solaris, the message is like:
127.0.0.1 - - [19/Nov/2009:04:42:16 -0600] "GET /ahe/cgi-bin/webcheck HTTP/1.0" 200 15 "-" "-"
Attention is: there is no "\\n" following the "HTTP/1.0". Does this mean something?
Really need help, this blocks me for several days!
If this is a name-based server, you'll need to use HTTP/1.1 and send a Host: header containing the hostname (domain name):
Host: www.example.com<newline>
GET /ahe/cgi-bin/webcheck HTTP/1.1<newline>
<newline>
However, the main problem appears to be that there is some syntax difference between Linux and Solaris. Solaris is converting your command-line "\n" to a newline, while Linux is not; Linux is sending it as a literal "\n" string, and this string is not valid for an HTTP request.
There may be some command line 'trick' you can do to force Linux to do the same thing. If not, you may have to move the HTTP request 'text' into a file, and use the command line to send that file instead of trying to embed the HTTP request line in the command line itself.
Jim