[dancer-users] Before Hook hit multiple times.

Brian E. Lozier brian at massassi.com
Thu Jan 3 00:47:00 GMT 2013


On Wed, Jan 2, 2013 at 4:20 PM, Rick Bragg <rbragg at gmnet.net> wrote:

>
>
> >
> > On 2013-01-02, at 5:35 PM, Puneet Kishor wrote:
> >
> >> On Jan 2, 2013, at 2:27 PM, David Golden <xdg at xdg.me> wrote:
> >>
> >>> On Wed, Jan 2, 2013 at 5:16 PM, Rick Bragg <rbragg at gmnet.net> wrote:
> >>>> hooks and routes are called once in the application flow.  Do I
> really have to
> >>>> program around this taking into consideration the number of times the
> before
> >>>> hook
> >>>> is called on each page?
> >>>
> >>> HTTP is stateless.  The client can make as many requests as it likes
> >>> and your Dancer app will see them as separate requests.
> >>>
> >>> The 'before' hook fires for every request.  If you want to limit a
> >>> hook to particular routes, you have to write that logic yourself in
> >>> the hook subroutine or else wrap the route handlers instead of using a
> >>> before hook.
> >>
> >> While the above explanation makes sense, and understanding it can lead
> to
> >> designing applications better, my gut feeling is with Rick. If I create
> a
> >> 'before' hook, I want it normally to fire once everything the human
> user makes a
> >> request even though under the scene the browser is making multiple
> requests. In
> >> other words, the current behavior seems to be against the DWIM nature
> that I
> >> would expect.
> >>
> >> Dancer being the new, easy way of developing apps, should perhaps have
> two kinds
> >> of hooks -- one that behaves the current way, and another that fires
> the way
> >> Rick, myself, and I suspect many other Dancer users expect it to
> behave, that is,
> >> once per human user request.
> >
> > If the before hook is firing on each request for static content (like
> favicon.ico),
> > why even bother serving it up via the app?  You can handle that via
> > https://metacpan.org/module/Plack::Middleware::Static or in your web
> server config.
> > In most cases you don't even want the app to know about static files.
> >
> > Olaf
> > --
> > Olaf Alders
> > olaf at wundersolutions.com
> >
> > http://www.wundersolutions.com
> > http://twitter.com/wundercounter
> >
> > 866 503 2204 (Toll free - North America)
> > 416 944 8306 (direct)
> >
>
> I'm using plack and I have apache set up to serve the "public" directory
> directly... so... I still don't get why the multiple calls to the before
> hook...
>
> Rick
>
>
>
Are you doing any ajax calls?  Or perhaps requests that redirect, for
example, are you hitting http://yoursite/ which then redirects to
http://www.yoursite/?  Can you print the full URL that's being hit in the
call so you can see if it's the exact same URL or something different?  As
others have mentioned, by default browsers look for that favicon.ico file
in your web root, so it doesn't matter if you're serving /public/ through
apache, since the request isn't looking for /public/favicon.ico, it's
looking for /favicon.ico.

I haven't seen any behavior indicating that multiple calls to any hooks
happen unless multiple requests are happening, so I think you should keep
looking for the cause of the multiple requests, not the same request
hitting the hook multiple times.  Of course, there could be some bug that I
haven't run into, but based on your messages so far, I really think you're
dealing with multiple requests coming in "around" the same time.  Can you
check your request (access) log before and after you hit the page?


>
>
>
> _______________________________________________
> dancer-users mailing list
> dancer-users at dancer.pm
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20130102/0f79d463/attachment.htm>


More information about the dancer-users mailing list