logo       

Re: mod_perl 2.0 api and extending method in Apache: msg#00285

apache.mod-perl

Subject: Re: mod_perl 2.0 api and extending method in Apache

Alexandre Dulaunoy wrote:
Hello,

I have look around the documentation of mod_perl 2.0 and I'm looking if it's possible with the current mod_perl API to add a method (like GET, HEAD) in apache to extend the functionnaly of the HTTP server ?
There is also some possibility with the new framework to add new protocol (like the echo example in the mod_perl doc). But I just want to extend existing (or add new) method... Is it possible ?

I'm not sure what you mean by extending, but look at mod_dav which extends the HTTP protocol: modules/dav/main/mod_dav.c (inside the httpd-2.0 repository).

In mod_perl 2.0 you can support new request methods, by simply registering them. e.g. let's support the method 'TNT' in the response handler:

<Location /extend>
SetHandler perl-script
PerlResponseHandler Apache::Extend
</Location>

package Apache::Extend;

use strict;
use warnings;

use Apache::RequestRec ();
use Apache::RequestIO ();
use Apache::RequestUtil ();

use Apache::Const -compile => 'OK';

use constant METHNAME => 'TNT';

sub handler {
my $r = shift;
$r->content_type('text/plain');

Apache::method_register($r->pool, METHNAME);

print "Called with Method: " . $r->method;

Apache::OK;
}

1;

Now, let's call:

perl -le 'require LWP::UserAgent; print LWP::UserAgent->new->request(HTTP::Request->new("GET", "http://localhost:8002/extend/";))->content;'
Called with Method: GET

__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@xxxxxxxxxx http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise