Re: ZPublisher events before streaming a response

Martin Aspeli <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <[email protected]>
Hanno Schlichting wrote:
> On Sun, Mar 21, 2010 at 10:07 AM, Martin Aspeli
> <[email protected]>  wrote:
>> We'd therefore like to add a new event in the HTTPResponse class (in
>> ZServer, though I think it makes sense to add to the ZPublisher base
>> class version as well). It'd hook in something like this:
>>
>>      if not self._wrote:
>>
>>          # new event code
>>          site = getSite()
>>          request = getattr(site, 'REQUEST', None)
>>          notify(PubBeforeStreaming(request))
>>
>>          # continue as before...
>>
>> (I couldn't find a better way to get hold of the request from a method
>> in the response, without adding a dependency on five.globalrequest,
>> which I assume is not desirable).
>>
>> Any objections? We need this in Zope 2.12, though I'll obviously merge
>> to trunk, too.
>
> Why would you need to have the event on the request, if all you want
> is to set headers? Why not make it an event with the response as the
> argument instead?

Mainly because that's what all the other IPub* events carry with them. 
We discovered this omission implementing plone.caching, which only needs 
the response, but it's not all that unlikely that something else may 
need the request.

Of course, "something else" could do the same getSite() trick if needed, 
or use five.globalrequest.

Martin

-- 
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.