Adding args to a Request through InputFilter
Hi, I would like to add args to a request on the fly thanks to an InputFilter. It seems like the $f->r->args($new_args) doesn't record the new argument inside the request. For example : Inside the filter : sub handler{ my ($f, $bb, $mode, $block, $readbytes) = @_; # filter args # $mode, $block, $readbytes are passed only for input filters my $rv = $f->next->get_brigade($bb, $mode, $block, $readbytes); return $rv unless $rv == APR::Const::SUCCESS; print STDOUT "Perlfilter : Uri = ", $f->r->uri(),"\n"; print STDOUT $f->r->args(),"\n"; #No argument $f->r->args("userId=10"); print STDOUT $f->r->args(),"\n"; #Returns the arg I passed } In a running perl script on my apache the $r->args() doesn't return anything. As I'm a newbie using mod_perl, a little help would be appreciated :) Ivory -- View this message in context: http://old.nabble.com/Adding-args-to-a-Request-through-InputFilter-tp27228223p27228223.html Sent from the mod_perl - General mailing list archive at Nabble.com.
Re: Adding args to a Request through InputFilter
Thanks for your explanation concerning the request processing (I think it corresponds to the drawing I've seen http://perl.apache.org/docs/2.0/user/handlers/http_cycle.gif here ) I understand it much better now :) The fact is that in order to add this arg to the request I need to call several Web services, crypt and decrypt datas and access the cookies I've previously stored in the clients navigator. Is it also possible in this type of handler? (I've already tested all these actions in an InputFilter and it works fine). Thanks again. Ivory Torsten Foertsch wrote: > > On Tuesday 19 January 2010 17:11:03 Ivory wrote: >> I would like to add args to a request on the fly thanks to an >> InputFilter. >> >> It seems like the $f->r->args($new_args) doesn't record the new argument >> inside the request. >> >> For example : >> >> Inside the filter : >> sub handler{ >> >> my ($f, $bb, $mode, $block, $readbytes) = @_; # filter args # $mode, >> $block, $readbytes are passed only for input filters >> >> my $rv = $f->next->get_brigade($bb, $mode, $block, $readbytes); >> return $rv unless $rv == APR::Const::SUCCESS; >> >> print STDOUT "Perlfilter : Uri = ", $f->r->uri(),"\n"; >> print STDOUT $f->r->args(),"\n"; #No argument >> $f->r->args("userId=10"); >> print STDOUT $f->r->args(),"\n"; #Returns the arg I passed >> } >> >> In a running perl script on my apache the $r->args() doesn't return >> anything. >> >> As I'm a newbie using mod_perl, a little help would be appreciated :) >> > What do you want to achieve? > > In general I'd not recommend to change $r->args in a filter because a > filter > is run when input is consumed and that is somewhat besides the normal > program > flow. > > Normally apache consumes input only in the response phase. A handler like > the > default handler that has no use for input calls ap_discard_request_body() > and > thus reads the input calls all input filters and puts the result in the > bin. A > handler like mod_cgi processes the input but again, it consumes it only in > the > response phase. CGI environment variables are set earlier. So changing $r- >>args in a filter cannot affect them. > > Instead use a PerlFixupHandler or so. > > PerlFixupHandler "sub {$_[0]->args(q{userId=10});0;}" > > Torsten > > -- View this message in context: http://old.nabble.com/Adding-args-to-a-Request-through-InputFilter-tp27228223p27239686.html Sent from the mod_perl - General mailing list archive at Nabble.com.
Re: Adding args to a Request through InputFilter
Hi , I've manage to setup a PerlFixupHandler, and it works perfectly well for adding / deleting headers and args. But it seems like this process is pretty time-consuming... Any known issue about that? Ivory Torsten Foertsch wrote: > > On Wednesday 20 January 2010 11:40:43 Ivory wrote: >> The fact is that in order to add this arg to the request I need to call >> several Web services, crypt and decrypt datas and access the cookies I've >> previously stored in the clients navigator. >> > yes. > > Cookies come in as HTTP headers. So $r->headers_in->{Cookie} can be used. > > Torsten > > -- View this message in context: http://old.nabble.com/Adding-args-to-a-Request-through-InputFilter-tp27228223p27274143.html Sent from the mod_perl - General mailing list archive at Nabble.com.
Re: Adding args to a Request through InputFilter
You were right, after reviewing my code it works much better :) Thanks again. Ivory Torsten Foertsch wrote: > > If "pretty time-consuming" means a few microseconds then yes, it may be > modperl. > > If more, it's your code. > > To figure out how much mod_perl costs try fetching a small static file > with > and without this lines: > > --- > > sub My::Handler::handler {0} > > > PerlFixupHandler My::Handler > --- > > Use "ab -n 1 -c 1 http://..."; and compare the results. > > Then add your fixup code and try again. > > Torsten > > -- View this message in context: http://old.nabble.com/Adding-args-to-a-Request-through-InputFilter-tp27228223p27355930.html Sent from the mod_perl - General mailing list archive at Nabble.com.