Re: Where best to intercept a request to send a 304 response in Zope 2

Laurence Rowe <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <[email protected]>
2009/12/31 Martin Aspeli <[email protected]>:
> Hi,
>
> A few of us are playing with some caching tools, trying to get to a more
> sane and less monkey patch-laden approach than CacheFu
> (Products.CacheSetup), for use with Zope 2.12.
>
> It is relatively easy to set response headers, e.g. in an
> IPubBeforeCommit event handler.
>
> However, we also need to be able to intercept a request to send a 304
> response if the underlying object has not been modified.
>
> CacheFu monkey patches ZPT rendering to avoid the actual rendering if a
> 304 response is being sent, returning an empty string instead. I'd
> rather not have such patches, though, and anyway this only work with
> things rendered as ZPTs. It also doesn't avoid any pre-work that a view
> may do before rendering its template, if indeed it has one.
>
> Another thought was to use IPubAfterTraversal, at which point we have
> the object to publish and security checks have been completed. However,
> ZPublisher.Publish goes straight from that into mapply().
>
> Can anyone think of a good way to do this? Maybe we need to add some
> kind of condition around mapply(), e.g. to do not nothing if there's a
> 304 response header, or some other marker?

I think this is analogous to 404 Not Found errors. It should be
possible to handle them with the combination of:

  * raise a NotModified exception in an IPubAfterTraversal handler
  * in a NotModified exception view, setStatus 304 Not Modified an
return an empty string.

Laurence
_______________________________________________
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.