Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

mod_perl and http status codes

by clintonm9 (Sexton)
on Mar 04, 2010 at 18:04 UTC ( #826769=perlquestion: print w/replies, xml ) Need Help??

clintonm9 has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a RESTFul mod_perl program and having a hard time sending different http status codes back to the client. I am currently using the Apache2::Registry handler. I have tried many different wants to send back a different status code with no luck.
my($r) = shift; $r->status_line("401");
I have also tried with no luck:
return Apache2::Const::HTTP_UNAUTHORIZED;
return Apache2::Status::HTTP_UNAUTHORIZED;
Do i have to write my own handle to send back different error status?

Replies are listed 'Best First'.
Re: mod_perl and http status codes
by jdrago999 (Pilgrim) on Mar 04, 2010 at 23:44 UTC

    Works like this:

    package My::Handler; use strict; use warnings 'all'; use Apache2::RequestRec; sub handler : method { my ($class, $r) = @_; $r->status( 401 ); return 401; } 1;# return true:
      Thank you that worked!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://826769]
Approved by Corion
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2021-06-13 11:03 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (54 votes). Check out past polls.