Re: Apache2::Request in PerlInitHandler and PerlAuthenHandler - modperl

This is a discussion on Re: Apache2::Request in PerlInitHandler and PerlAuthenHandler - modperl ; Hi. It usually helps for any kind of support issue, if you provide some information about where this is happening : what platform, which Apache version, which perl version, which mod_perl version, etc.. Now, below : > SetHandler perl-script is ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Re: Apache2::Request in PerlInitHandler and PerlAuthenHandler

  1. Re: Apache2::Request in PerlInitHandler and PerlAuthenHandler

    Hi.

    It usually helps for any kind of support issue, if you provide some
    information about where this is happening : what platform, which Apache
    version, which perl version, which mod_perl version, etc..

    Now, below :
    > SetHandler perl-script

    is used when your purpose is to run a "traditional" cgi-bin script under
    mod_perl, not for embedded modules like your
    > PerlResponseHandler ARULink::handler

    would indicate.
    I suggest you try replacing this first by
    SetHandler modperl

    For the same reason, the line
    > Options ExecCGI

    is not necessary, since you are not executing any cgi-bin scripts in
    that directory, only mod_perl handlers.

    Additionally, I am not quite sure of your line
    > my $cgi = CGI->new($req_params);

    I believe you should rather use
    > my $cgi = CGI->new($req);

    The CGI.pm module is smart enough, given the correct environment, to
    figure out that it is running under mod_perl, and then use the request
    object ($req) as a base to build the CGI object.

    The above may well be why the CGI.pm library module is getting confused,
    and spinning. So try the changes first, and come back if it still has a
    problem.


    Shibi NS wrote:
    > I have following Location directive in my applications conf file
    >
    >
    > PerlInitHandler ARULink::setup_request
    > SetHandler perl-script
    > PerlResponseHandler ARULink::handler
    > PerlOptions +ParseHeaders +GlobalRequest
    > Options ExecCGI
    > AuthName Metalink
    > AuthType Basic
    > PerlAuthenHandler ARULink::MetalinkAuth
    > require valid-user
    > ErrorDocument 401 /handle_auth_failure
    >

    >
    >
    > And the ARULink::MetalinkAuth::handler is
    >
    > sub handler
    > {
    > my ($req) = @_;
    >
    > my $status;
    > my $username;
    > my $userid;
    > my $email;
    >
    > #
    > # Create a Session object.
    > #
    > my $req_params = $req->args;
    > my $cgi = CGI->new($req_params);
    > my $session = ARU::Session::get_cgi_session($cgi);
    > $req->subprocess_env;
    >
    > ....
    > }
    >
    > When my handler reaches line '(my $cgi = new CGI($params)' the
    > application is spinning ,seems like $req->args is returning null and
    > application line number 354 of CGI which is $req->subprocess_env;
    >
    > Error from log file
    >
    > Warning:
    > Deep recursion on subroutine "CGI::new" at /m/isd/pm/ARULink/MetalinkAuth.pm
    > line 114.
    >
    >
    > Line File Sub Called Arg
    > WntA
    > ---- ---- ---------- ---
    > ----
    > 359 Debug.pm Debug::stack_trace Y
    > N
    > 114 MetalinkAuth.pm Debug::__ANON__ Y
    > N
    > 114 MetalinkAuth.pm CGI::new Y
    > N
    > 354 CGI.pm ARULink::MetalinkAuth::handler Y
    > N
    >
    > ..
    >
    > Any idea how can we get the $req->args which contains request information
    > in PerlAuthenHandler or PerlInitHandler
    >
    > --Shibi Ns--
    >



  2. Re: Apache2::Request in PerlInitHandler and PerlAuthenHandler

    On Tue 14 Oct 2008, Shibi NS wrote:
    > And the ARULink::MetalinkAuth::handler is
    >
    > sub handler
    > {
    > my ($req) = @_;
    >
    > my $status;
    > my $username;
    > my $userid;
    > my $email;
    >
    > #
    > # Create a Session object.
    > #
    > my $req_params = $req->args;
    > my $cgi = CGI->new($req_params);
    > my $session = ARU::Session::get_cgi_session($cgi);
    > $req->subprocess_env;
    >
    > ....
    > }
    >
    > When my handler reaches line '(my $cgi = new CGI($params)' the
    > application is spinning ,seems like $req->args is returning null and
    > application line number 354 of CGI which is $req->subprocess_env;
    >
    > Error from log file
    >
    > Warning:
    > Deep recursion on subroutine "CGI::new" at
    > /m/isd/pm/ARULink/MetalinkAuth.pm line 114.


    Don't know about CGI in this context but is there any chance to switch
    to Apache2::Request (libapreq2)?

    If you really see an empty $r->args at that stage while you are certain
    to have passed something then it is an error in mod_perl. Try to create
    a test case as short and simple as you can and file a bugreport.

    Try something like

    warn "params: ".$req->args;

    The warning will appear in the error_log.

    Can you please be more detailed about where it spins in CGI.pm? My
    version 3.29 looks like:

    350 if ($MOD_PERL) {
    351 if ($MOD_PERL == 1) {
    352 $self->r(Apache->request) unless $self->r;
    353 my $r = $self->r;
    354 $r->register_cleanup(\&CGI::_reset_globals);
    355 }
    356 else {
    357 # XXX: once we have the new API
    358 # will do a real PerlOptions -SetupEnv check
    359 $self->r(Apache2::RequestUtil->request) unless $self->r;
    360 my $r = $self->r;
    361 $r->subprocess_env unless exists $ENV{REQUEST_METHOD};
    362 $r->pool->cleanup_register(\&CGI::_reset_globals);
    363 }
    364 undef $NPH;
    365 }

    Line 354 is somewhere in the mp1 code path. The mp2 code path looks
    correct for me. Apache2::RequestUtil->request is set up in
    postreadrequest and again in headerparser if +GlobalRequest.
    cleanup_register() is also allowed here.

    Ah, does your code check for a subrequest? Something like "return ... if
    $r->main" or "return ... unless $r->is_initial_req"? If not you may see
    it spinning in the subprocess_env line if your $r->path_info is not
    empty. The reason is a subrequest issued during $r->subprocess in void
    context to compute the standard CGI variable $ENV{PATH_TRANSLATED}.
    Apache does that by $r->lookup_uri($r->path_info). Assuming you don't
    have a download, ARULink or WebApp directory in your DocumentRoot the
    whole URI will be in $r->path_info as well. So, the subrequest will hit
    the same location container an thus the authen handler. Just a guess.

    On Tue 14 Oct 2008, André Warnier wrote:
    > Now, below :
    > *> SetHandler * * * * * * *perl-script
    > is used when your purpose is to run a "traditional" cgi-bin script
    > under mod_perl, not for embedded modules like your
    > *> PerlResponseHandler * * ARULink::handler
    > would indicate.
    > I suggest you try replacing this first by
    > SetHandler modperl


    Sorry André but that is not entirely true. perl-script vs. modperl
    simply means you want the more sophisticated response handler. It
    affects only the response phase. Since the authen handler comes prior
    to that it is irrelevant here. More sophisticated means you want %ENV
    tied to $r->subprocess_env, tied *STDIN, *STDOUT, etc. The main reason
    for me to avoid the perl-script handler is that it uses PerlOptions
    +SetupEnv as default. That calls ap_add_cgi_vars() and that computes
    $ENV{PATH_TRANSLATED} the IMHO most useless CGI variable. To do that it
    issues a subrequest.

    Torsten

    --
    Need professional mod_perl support?
    Just hire me: torsten.foertsch@gmx.net


  3. Re: Apache2::Request in PerlInitHandler and PerlAuthenHandler

    Torsten Foertsch wrote:
    > On Tue 14 Oct 2008, Shibi NS wrote:
    >> And the ARULink::MetalinkAuth::handler is
    >>
    >> sub handler
    >> {
    >> my ($req) = @_;
    >>
    >> my $status;
    >> my $username;
    >> my $userid;
    >> my $email;
    >>
    >> #
    >> # Create a Session object.
    >> #
    >> my $req_params = $req->args;
    >> my $cgi = CGI->new($req_params);
    >> my $session = ARU::Session::get_cgi_session($cgi);
    >> $req->subprocess_env;
    >>
    >> ....
    >> }
    >>
    >> When my handler reaches line '(my $cgi = new CGI($params)' the
    >> application is spinning ,seems like $req->args is returning null and
    >> application line number 354 of CGI which is $req->subprocess_env;
    >>
    >> Error from log file
    >>
    >> Warning:
    >> Deep recursion on subroutine "CGI::new" at
    >> /m/isd/pm/ARULink/MetalinkAuth.pm line 114.

    >
    > Don't know about CGI in this context but is there any chance to switch
    > to Apache2::Request (libapreq2)?
    >
    > If you really see an empty $r->args at that stage while you are certain
    > to have passed something then it is an error in mod_perl. Try to create
    > a test case as short and simple as you can and file a bugreport.
    >
    > Try something like
    >
    > warn "params: ".$req->args;
    >
    > The warning will appear in the error_log.
    >
    > Can you please be more detailed about where it spins in CGI.pm? My
    > version 3.29 looks like:
    >
    > 350 if ($MOD_PERL) {
    > 351 if ($MOD_PERL == 1) {
    > 352 $self->r(Apache->request) unless $self->r;
    > 353 my $r = $self->r;
    > 354 $r->register_cleanup(\&CGI::_reset_globals);
    > 355 }
    > 356 else {
    > 357 # XXX: once we have the new API
    > 358 # will do a real PerlOptions -SetupEnv check
    > 359 $self->r(Apache2::RequestUtil->request) unless $self->r;
    > 360 my $r = $self->r;
    > 361 $r->subprocess_env unless exists $ENV{REQUEST_METHOD};
    > 362 $r->pool->cleanup_register(\&CGI::_reset_globals);
    > 363 }
    > 364 undef $NPH;
    > 365 }
    >
    > Line 354 is somewhere in the mp1 code path. The mp2 code path looks
    > correct for me. Apache2::RequestUtil->request is set up in
    > postreadrequest and again in headerparser if +GlobalRequest.
    > cleanup_register() is also allowed here.
    >
    > Ah, does your code check for a subrequest? Something like "return ... if
    > $r->main" or "return ... unless $r->is_initial_req"? If not you may see
    > it spinning in the subprocess_env line if your $r->path_info is not
    > empty. The reason is a subrequest issued during $r->subprocess in void
    > context to compute the standard CGI variable $ENV{PATH_TRANSLATED}.
    > Apache does that by $r->lookup_uri($r->path_info). Assuming you don't
    > have a download, ARULink or WebApp directory in your DocumentRoot the
    > whole URI will be in $r->path_info as well. So, the subrequest will hit
    > the same location container an thus the authen handler. Just a guess.
    >
    > On Tue 14 Oct 2008, André Warnier wrote:
    >> Now, below :
    >> > SetHandler perl-script

    >> is used when your purpose is to run a "traditional" cgi-bin script
    >> under mod_perl, not for embedded modules like your
    >> > PerlResponseHandler ARULink::handler

    >> would indicate.
    >> I suggest you try replacing this first by
    >> SetHandler modperl

    >
    > Sorry André but that is not entirely true. perl-script vs. modperl
    > simply means you want the more sophisticated response handler. It
    > affects only the response phase. Since the authen handler comes prior
    > to that it is irrelevant here. More sophisticated means you want %ENV
    > tied to $r->subprocess_env, tied *STDIN, *STDOUT, etc. The main reason
    > for me to avoid the perl-script handler is that it uses PerlOptions
    > +SetupEnv as default. That calls ap_add_cgi_vars() and that computes
    > $ENV{PATH_TRANSLATED} the IMHO most useless CGI variable. To do that it
    > issues a subrequest.
    >

    I mentioned that mainly because I thought it might have something to do
    with the convoluted gymnastics that CGI.pm does to try and figure out if
    it is running under mod_perl, and under which version of it.

    But anyway, there is no reason to use perl-script here rather than
    mod_perl. It adds overhead, without bringing any benefit in this case.
    I believe the problem might be more tied to the following lines :

    >> my $req_params = $req->args;
    >> my $cgi = CGI->new($req_params);


    Is CGI really expecting in this case to receive the $r->args as argument
    to new() ?
    Looking at the code, it seems to expect various things in various
    devious ways, but $r->args does not seem to be one of them.

    There is by the way a certain lack of documentation about the behaviour
    of CGI.pm under mod_perl. It is mentioned in some obscure place that
    CGI is "aware" of mod_perl, but not much more.
    Not in CGI.pm documentation at any rate.


  4. Re: Apache2::Request in PerlInitHandler and PerlAuthenHandler

    On Wed, Oct 15, 2008 at 2:44 AM, Shibi NS wrote:
    > CGI.pm version 3.15


    Update.

    - Perrin


  5. Re: Apache2::Request in PerlInitHandler and PerlAuthenHandler

    Thanks All for the valuable suggestions. my $cgi = CGI->new($req); fixed
    my issue

    On Thu, Oct 16, 2008 at 2:04 AM, Perrin Harkins wrote:

    > On Wed, Oct 15, 2008 at 2:44 AM, Shibi NS wrote:
    > > CGI.pm version 3.15

    >
    > Update.
    >
    > - Perrin
    >




    --
    --Shibi Ns--


+ Reply to Thread