[Zope-dev] ZPublisher events before streaming a response

Tres Seaver tseaver at palladion.com
Sun Mar 21 08:17:26 EDT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin Aspeli wrote:
> Hi,
> 
> In some cases (e.g. large OFS.File/Image responses), Zope 2 will use 
> response.write() to stream the response.
> 
> We have events that fire before and after a "regular" response is 
> returned, but none that allow us to set headers (caching headers, in 
> this case) before such a streaming response is calculated. The normal 
> events fire too late.
> 
> 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.

I don't understand the need.  The OFS.Image module uses RESPONSE.write
in three methods:

- - _range_request_handler

- - index_html

- - manage_FTPget

Of these, only 'index_html' is reasonable for setting HTTP cache
headers, and it already has built-in support for that, via the
ZCacheable API.  In particular, this support is how the "file stream
iterator" bits get done, which is way more optimal than falling through
to the RESPONSE.write calls.

No other code in Zope2 proper (or its dependent eggs) calls
RESPONSE.write att all:

 $ find src -name "*.py" | xargs grep -li "response\.write("
 src/Testing/tests/test_makerequest.py
 src/OFS/Image.py
 $ find eggs -name "*.py" | xargs grep -li "response\.write("
 $

I'm -1 on adding the event without more justification.



Tres.
- --
===================================================================
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkumDlEACgkQ+gerLs4ltQ5MwwCgmgjC803AqjWCZEja1Hma1iz8
WXIAoMp/1Jay5I2Va/Y1bzbvRpcxvoek
=H+DL
-----END PGP SIGNATURE-----



More information about the Zope-Dev mailing list