perlapacheapache2mod-perlmod-perl2

How do I suppress the default apache error document in mod_perl?


I'm developing a RESTful API and I wrote a mod_perl2 handler that takes care of the request.

My handler deals with error codes by setting $r->status($http_code) and return $http_code;

Everything is fine, except a little problem: when my http_code is different than 200 (for instance 404), apache appends a default HTML error document to my own generated response.

For instance:

GET /foo

Gives:

$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>

How do I get rid of this apache generated HTML?

UPDATE: My fault. My mod_perl2 handler was returning a HTTP_* code instead of Apache2::Const::OK.


Solution

  • See Apache2::Response. I do not have time to experiment right now, but that should work.