Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

mod_perl and http status codes

by clintonm9 (Sexton)
on Mar 04, 2010 at 18:04 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-09-17 18:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (22 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.