Re: [mp2] reliable methods to prevent handlers from repeating

[prev] [thread] [next] [Date index for 2005/01/20]

From: Philippe M. Chiasson
Subject: Re: [mp2] reliable methods to prevent handlers from repeating
Date: 22:32 on 20 Jan 2005
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enigFDC1CE595157ABED138FF4F6
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Dorian Taylor wrote:
> suppose i wanted the same logic as:
> 
>     return Apache::DECLINED unless $r->is_initial_req;
> 
> except that sometimes it may be necessary to serve for a subrequest,
> just not more than once. the construct i tried is:
> 
>     for (my $pr = $r; $pr; $pr = $pr->prev) {
>         if ($pr->notes->get(__PACKAGE__ . '::SEEN')) {
>             $r->log->debug("We've been seen already.");
>             return Apache::DECLINED;
>         }       
>     }
>     $r->notes->set(__PACKAGE__ . '::SEEN', 1);

That's because you are setting that SEEN flag in the subrequest itself,
and that subrequest will most likely be short lived. Nobody will see that
flag, unless that subrequest fires off another subrequest of it's own.

What you are trying to do is probably :

$r->main->notes->set(__PACKAGE__ . '::SEEN', 1);

And then your check becomes

$r->main->notes->get(__PACKAGE__ . '::SEEN');

Without a need to cycle over the requests list either.

--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5

--------------enigFDC1CE595157ABED138FF4F6
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFB8DGbyzKhB4jDpaURArJ4AJ90VOp41ry6psz64QzN8QNme2htbwCfTToE
puO24XECHOiLmjlyyHj+SdI=
=Ojkq
-----END PGP SIGNATURE-----

--------------enigFDC1CE595157ABED138FF4F6--

Re: [mp2] reliable methods to prevent handlers from repeating
Philippe M. Chiasson 22:32 on 20 Jan 2005

Generated at 17:42 on 27 Jan 2005 by mariachi v0.52