我正在开发一个 RESTful API,并编写了一个处理请求的 mod_perl2 处理程序。
我的处理程序通过设置$r->status($http_code)
和return $http_code;
一切都很好,除了一个小问题:当我的 http_code 不是 200(例如 404)时,apache 会在我自己生成的响应中附加一个默认的 HTML 错误文档。
例如:
GET /foo
给出:
$VAR1 = bless( {
'status' => 404,
'data' => {},
'message' => 'Resource not found for foo'
}, 'My::Response' );
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /foo was not found on this server.</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
<hr>
<address>Apache/2.0.54 (Fedora) Server at localhost Port 80</address>
</body></html>
如何摆脱这个 apache 生成的 HTML?
更新:我的错。我的 mod_perl2 处理程序返回的是 HTTP_* 代码,而不是 Apache2::Const::OK。