Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache/2.2.9, mod_perl/2.0.4: status_line doesn't seem to work

Response is prepared this way:

my $r = Apache2::RequestUtil->request;
$r->status_line('500 Internal Server Error');
$r->send_cgi_header("Content-Type: text/html; charset=UTF-8\n\n");
print 'Custom error message';

Request:

GET /test_page HTTP/1.1
Host: www.xxx.xxx

Response:

HTTP/1.1 200 OK
Date: XXXXXXXXXX
Server: Apache/xxxxxxxx
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

44
Custom error message
0

Why response status is 200 and not 500?


2 Answers

Is this a Registry script or a handler?

In a response handler, if you're setting a 4xx or 5xx status you need to return Apache2::Status::DONE rather than Apache2::Status::OK.

From http://perl.apache.org/docs/2.0/user/handlers/intro.html#Stacked_Handlers :

HTTP handlers may also return Apache2::Const::DONE which tells Apache to stop the normal HTTP request cycle and fast forward to the PerlLogHandler, followed by PerlCleanupHandler. HTTP handlers may return any HTTP status, which similarly to Apache2::Const::DONE will cause an abort of the request cycle, by also will be interpreted as an error. Therefore you don't want to return Apache2::Const::HTTP_OK from your HTTP response handler, but Apache2::Const::OK and Apache will send the 200 OK status by itself.

Hope that helps - I remember having to spend quite some time looking for this in the docs, I don't think it's mentioned anywhere else!

like image 136
John O'Rourke Avatar answered Dec 07 '25 16:12

John O'Rourke


$r->custom_response(500, $custom_error_message) must be used for this purpose.

like image 28
Eugene Toropov Avatar answered Dec 07 '25 16:12

Eugene Toropov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!