[Zope] Browser Sticky Fingers

Martijn Pieters mj@antraciet.nl
Wed, 20 Oct 1999 10:57:43 +0200


At 18:24 19/10/99 , Tony McDonald wrote:
>At 5:45 pm +0200 19/10/99, Peter Sabaini wrote:
>>possibly the src= of the <img> points to a cgi program that returns "Expires:
>>(something soon)" headers so it wont get cached.
>>
>>in perl pseudocode (sorry i'm not that accustomed to python yet) you'd write
>>something like this:
>>
>># this from thimble smith, tim@desert.net
>># read image data
>>$img = <wherever you get the image data from, gif assumed>
>># print expires with date=now
>>print "Expires: ", scalar(localtime), "\r\n";
>># or whatever content, then insert gif data
>>print "Content-type: image/gif\r\n\n$img"
>
>Neat!
>It looks like the place to change this is in the index_html method of 
>OFS/Image.py
>
>You *could* add an Expires header to the group of
>
>         RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
>         RESPONSE.setHeader('Content-Type', self.content_type)
>
>lines near the end of this method, but I think that will mean that *all* 
>images from a Zope system will be expired. A better solution would be if 
>you could send an Expires header to the Image object.

A better solution, immediatly applicable, is to use the 'precondition' 
property of the File and Image objects. On Image objects you can't edit 
this property via the management interface, but you can set it using an 
external method (imagename.precondition='precondition').

If the precondition attribute is set to a nonempty string, it is the name 
of a method to call. This could be anything callable.

It is expected to raise an error if certain conditions aren't met, for 
example, when someone doesn't have the right cookie to download a certain 
File. But it could also be used to manipulate the RESPONSE object. So if 
you make a method ExpireNow that doesn't do anything but do 
RESPONSE.setHeader('Expires', ZopeTime().rfc822()), and use an external 
method to set the image's precondition to ExpireNow, this _should_ work. I 
have not tested this though.

One caveat I can see with this method: If you click on the Change button on 
the Image Edit tab, the precondition attribute is set to ''.

You could create a ZClass based on Image that only defines a new edit 
screen that includes the precondition property, this would solve the need 
for an external method as well.

--
Martijn Pieters, Web Developer
| Antraciet http://www.antraciet.nl
| Tel: +31-35-7502100 Fax: +31-35-7502111
| mailto:mj@antraciet.nl http://www.antraciet.nl/~mj
| PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149
------------------------------------------