2

I've seen hundreds of pages explaining how to create custom error pages in Apache 2 server. My question is different. I have a web application running in Apache (it is a ISAPI DLL, but it could also be a CGI executable). My application can handle internal server errors and generate a detailed error message (for instance, include a full stack trace), included in the response together with error code 500. AFAIK, Apache just let me use redirection in order to display custom error messages: http://httpd.apache.org/docs/2.2/custom-error.html

HTTP spec (RFC 2616 - section 10), not only allows but also recommend that detailed error message should be included in the BODY section of the response in case of error code > 500. Link: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5

Seems that Apache won't let my custom error message go to the browser, and always replace it with its own internal error message and I believe that it is not the correct behavior, based on RFC 2616.

So my question is: Is there any setting in Apache server that will let my custom message go to the browser? Or, is there anything that can be done in my application that will instruct Apache to send my custom error message (something like some specific header field in the response)?

More on the subject: When my ISAPI application returns error code 500, with other error information in the response body, Apache replaces it with its standard "500 Internal Server Error" message/HTML content, and inside Error.log file I can see the "useless" "Premature end of script headers" message. I'm deeply sure that my headers are fine, including the Content-Type field. If I replace the 500 error code with any other server error code (e.g. 501) it works flawlessly and my response goes to the browser as is. The same header is sent to the Apache server, only the error code is different (501, instead of 500). With this test result in mind, one of these two must be true: 1- Apache requires some specific header field when status code is 500 2- Apache won't let custom error messages with status code 500 go to the browser. I don't see any other alternative.

Alexandre M
  • 1,146
  • 12
  • 23

1 Answers1

0

I think you're conflating two questions. You can generate a 500 response with a CGI script and include your custom body. Or you can override any 500 with any resource you want.

If you're failing to do the former, it's likely because of some subtle thing in the ISAPI interface between Apache and your module. Desk-checking the code says you should be able either set the pseudo

Status: 500

Header, or basically return any ISAPI error and end up with a 500 and your custom body.

Apache has two notions of a status code -- the one in the status line (r->status) and an error code returned separately from the module that handles the request (return HTTP_INTERNAL_SERVER_ERROR, return r->status).

When the former is used as the latter is when the custom error messages get lost. All of that happens in./modules/arch/win32/mod_isapi.c in Apache. Whatever is going on, it is ISAPI unique.

covener
  • 17,402
  • 2
  • 31
  • 45
  • Hi Covener, thanks for your response. I'm not sure if the problem relies inside my ISAPI module, once the same binary works perfectly fine in IIS 6, 7 and 7.5, and my custom error message (with error code = 500) is received by the browser and displayed to the user. Apache, on the other hand, only send its own standard 500 error page... – Alexandre M Mar 05 '14 at 13:00
  • 1
    I did another test: Instead of sending the 500 error code in my response header, I'm sending a 200 code and the rest of the response is the SAME. If there was a problem with my ISAPI application, Apache should also report it as a 500 error, correct? But it does not happen. In this case, the complete response gets to the browser, untouched. I can only suppose that Apache do not let ISAPI responses with error code 500 go to the browser, and replace the body content with its own standard error message. – Alexandre M Mar 05 '14 at 23:35
  • Hello, Were you able to find a solution to this? We are also facing same issue with Apache 2.4. We are trying to send in a custom message via our servlet for code 409 and 500 which gets overridden by Apache server and it sends in the default body. – TechNiks Jan 30 '20 at 08:15