简体   繁体   中英

mod_perl How to return 511 status?

I am writing perl handler for Apache2.

This is my config:

PerlModule xxx::andsf 
<Location / >
  SetHandler perl-script
  PerlHandler xxx::andsf
  PerlSendHeader On
</Location>

My handler need to return to client 511 HTTP Status code. You can read about 511 here:

if my code return 505; I receive correct status 505 HTTP Version not supported . But if I put return 511; I get 500 - Internal server error. It seems Apache ignoring strange error code.

Any ideas how to return 511?

Update handler's code:

package xxx::andsf;
use Apache2::Const
  qw( :common );
use Apache2::RequestRec ();
use Apache2::RequestIO  ();

sub handler {
  my $r = shift;
  $r->status_line("511 Network Authentication Requred");
  return Apache2::Const::OK;
}
1;

ModPerl 2?

You can use $r->status_line("511 Network Authentication Requred") and then return Apache2::Const::OK (0)

See: http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_status_line_

I solved that issue. It has nothing to do with ModPerl2 but Apache itself. It is not a problem for Apache 2.4 only 2.2 affected. After looking into Apache 2.2 source code and patching some lines to accept 511 (you can copy/paste those lines from source of Apache 2.4) it starts correctly to return code 511.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM