Why does Apache + Rails spit out two status headers for 500 code?

I have a rails application that works fine except for one thing.

When I ask for something that does not exist (i.e. / not_a_controller_or_file.txt), and the rails throw an exception “No match route ...”, the answer is this (empty line intentionally):

HTTP/1.1 200 OK Date: Thu, 02 Oct 2008 10:28:02 GMT Content-Type: text/html Content-Length: 122 Vary: Accept-Encoding Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Status: 500 Internal Server Error Content-Type: text/html <html><body><h1>500 Internal Server Error</h1></body></html> 

I have an ExceptionLogger plugin in / vendor, although this does not seem to be a problem. I have not added any error handling outside of the user 500.html publicly (although the answer does not contain this HTML), and I do not know where this html bit comes from.

So, something, somewhere adds that the HTTP / 1.1 status code 200 is too early, or Status: 500 is too late. I suspect this is Apache because I get the corresponding HTTP / 1.1 500 header (above) when I use Webrick.

My production stack looks like this: Apache 2 Mongrel (5 instances) RubyOnRails 2.1.1 (happens both in versions 1.2 and 2.1.1)


I forgot to mention, the error is caused by the exception "no route matches ..."

+4
source share
3 answers

This is a pretty old thread, but for what it's worth, I found a great resource that includes a detailed description of the problem and solution. Apparently, this error affects Rails <2.3 when used with Mongrel.

+2
source

This html file comes from Rails. It encounters some kind of error (possibly an exception of some type or some other fatal error).

If an extra blank line is added between the Status header and the actual headers, and not just a typo, this will be a long explanation of why Apache reports a 200 OK message.

The status header is how Rails, PHP, or Apache says something. "An error has occurred, please return this code instead of 200 OK." The fact that there is an empty string means that something extra is going on, and Ruby displays the empty string before the error is output for any reason. Perhaps this is the previous result from your script. However, a long and short, extra empty line means that Apache thinks “Oh, empty line, no additional headers, this is all the content now”, which is consistent with the Content-Length header that you specified.

My guess is why the previous script output will be on the empty line, possibly the line ending at the end of the script page. As for why the 500 error occurs, there is not much information to tell you about this. There may be a file I / O error.

Edit: Given the additional information Dave provided about the internal components, I would say that this is actually a problem with proxying that happens behind the scenes ... I could not tell you exactly, though, in addition to what has already been said.

+1
source

It comes from the rails.

http://github.com/rails/rails/tree/master/actionpack/lib/action_controller/dispatcher.rb#L60

The dispatcher returns a page with a status code of 200 (Success).

0
source

Source: https://habr.com/ru/post/1277390/


All Articles