SPUG:CGI header question

Peter Darley pdarley at kinesis-cem.com
Thu Jun 19 12:33:43 CDT 2003


Simon,
	That's exactly what I was looking for. :)
	So, just to confirm, I would get this from the post or get request, compare
it to the timestamp of my image, and either return the image as normal or
return a header with status of 304 and no associated data.
	A couple of questions:  I can't find a way to get this info out of CGI.  It
seems like the documentation isn't complete for CGI... I use the function
virtual_host() from CGI, but I'll be darned if I can find any documentation
of it, and I have a feeling that there will be a similar function to get the
if-modified-since request header.  I'm sure I'm just missing something
obvious; if someone could direct me to some documentation that would be
grand.
	The second question is, does anyone know if this header is filled with the
date from the browser, or does it store a server generated date from the
returned header or something?  What will happen if the browser and server
don't agree on the time?
Thanks,
Peter Darley

-----Original Message-----
From: Simon Wilcox [mailto:essuu at ourshack.com]
Sent: Thursday, June 19, 2003 9:48 AM
To: Peter Darley
Cc: SPUG
Subject: Re: SPUG:CGI header question


On Thu, 2003-06-19 at 16:52, Peter Darley wrote:
> 	I'm working on a project where I'm storing media (photos, sound files) in
a
> database and serving them through a perl script.  My image tags look like
> <img src='Photo.pl?PhotoID=14232'>, which works fine.  What I'm looking
for
> advice on is that since this is a perl script browsers wont cache the
> result, so it wants to download the images again weither it is new or not.
> I can't find a way in the CGI module's header stuff to give a date or
> anything so the browser can decide weither it should be loaded from cache
or
> from the server.

Hi Peter,

Have a look at the headers the browsers are sending with their request.

There should be one named If-Modified-Since. You can compare this date
with the modified date of your image and return a 304 (Not Modified)
status code instead of 200. This will cause the browser to use the
cached image.

Normally this happens automatically for images in the filesystem but you
have to hand code it into CGI apps.

You could also try setting the 'expires' option in CGI. From the man
page:

print $q->header(-type=>'image/gif',-expires=>'+3d');

That should allow the browser to cache it without an extra request.

HTH,

Simon.





More information about the spug-list mailing list