2

响应是这样准备的:

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';

要求:

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

回复:

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

为什么响应状态是 200 而不是 500?

4

2 回答 2

1

这是注册表脚本还是处理程序?

在响应处理程序中,如果您要设置 4xx 或 5xx 状态,则需要返回Apache2::Status::DONE而不是Apache2::Status::OK.

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

HTTP 处理程序也可能返回 Apache2::Const::DONE,它告诉 Apache 停止正常的 HTTP 请求周期并快进到 PerlLogHandler,然后是 PerlCleanupHandler。HTTP 处理程序可以返回任何 HTTP 状态,类似于 Apache2::Const::DONE 将导致请求周期中止,也将被解释为错误。因此,您不想从 HTTP 响应处理程序返回 Apache2::Const::HTTP_OK,但 Apache2::Const::OK 和 Apache 将自行发送 200 OK 状态。

希望这会有所帮助——我记得我不得不在文档中花费相当多的时间来寻找这个,我认为其他任何地方都没有提到它!

于 2009-11-27T22:11:19.817 回答
1

$r->custom_response(500, $custom_error_message) 必须用于此目的。

于 2010-06-13T07:22:17.403 回答