Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

How do you run mod_perl handlers after standard Apache handlers

by EvdB (Deacon)
on Mar 14, 2003 at 15:57 UTC ( #243087=perlquestion: print w/replies, xml ) Need Help??

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

I have written a mod_perl handler that cooperates with the standard module mod_usertrack to look after cookies on the browser.

My handler lets mod_usertrack take care of putting the cookies out as required. To be able to get at the cookie value on the first request (ie when the cookie is going out for the first time) my module looks at $r->notes('cookie'), which is where apache puts the value.

My problem is that mod_usertrack runs at the fixup stage, which is when I want to run my handler as well. However as my handler takes precedence it is run first and so cannot get the cookie value. If I run it at the content stage all is fine.

Question: How can I make mod_usertrack run before my handler, or do I have to run my handler as a content handler rather than a fixup handler? Indeed if I wanted to access the cookie value from an even earlier handler how could that be done? The problem really is getting the value of the cookie on the way out for the first time, otherwise it is trivial.

-- tidiness is the memory loss of environmental mnemonics

Replies are listed 'Best First'.
Re: How do you run mod_perl handlers after standard Apache handlers
by perrin (Chancellor) on Mar 14, 2003 at 17:16 UTC
    AFAIK, you only have two choices. You can change one of the handlers to run at a different request stage, or you can replace mod_usertrack with Apache::Usertrack and used stacked handlers. Stacked handlers are only available for Perl handlers, so you can't do that with the original mod_usertrack.

    There may be some compiling trick to adjust which one runs first. Asking on the mod_perl list is your best bet for that.

      There may be some compiling trick to adjust which one runs first. Asking on the mod_perl list is your best bet for that.
      The running order is determined by the order in which the modules get registered, in inverse order. If you are using an Apache that uses dynamic loading, you can shuffle the order of the AddModule calls in the httpd.conf. mod_perl is normally last (or nearly last), so it runs first. If you put it ahead of mod_usertrack, it'll run after that.

      Beware... such shuffles will affect all phases, not just the one you are thinking about. Be very careful, and test on a test machine, not a production machine!

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

Re: How do you run mod_perl handlers after standard Apache handlers
by domm (Chaplain) on Mar 14, 2003 at 16:19 UTC
    I do not really know anything about mod_usertrack, but maybe you can tell it to run at different phase it the request cycle. To do this, you'll need to modify the C source code of mod_usertrack.

    At the end of mod_usertrack.c in (apache_1.3.xx/src/modules/standard) you'll find a large data structure. I do not know how much you know about mod_perl / Apache, but each entry in this list corresponds to one phase of the Request Cycle. You could try to move spot_cookie on line up, into the type_checker phase (be sure to replace it with NULL in the fixup phase). Recompile Apache. It might work, but I'm not sure...

    Or take a look at Apache::Usertrack, but is rather old and unfinished...

    And maybe somebody on the mod_perl mailing list knows better...

    -- #!/usr/bin/perl for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2021-09-21 08:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?