pesto.wsgiutils.serve_static_file should use "Last-Modified" header instead of "Last-Modified-Date"

22 views
Skip to first unread message

Samuel Wan

unread,
Aug 27, 2010, 7:34:49 PM8/27/10
to Pesto
Hi Oliver,

First of all, thank you for the pesto framework. It's very clean,
simple, and I hope to deploy a product with it soon.

In case this google group is active, I wanted to let you know I had
some difficulty getting static files to cache correctly. It turns out
that the wsgiutils.serve_static_file method adds a "Last-Modified-
Date" response header which isn't recognized in Firefox (and probably
other browsers). As a result, the browser does not send a "If-Modified-
Since" request header.

In order to get the browser to send an "If-Modified-Since" request
header, I first needed to add a "Last-Modified" response header
instead of "Last-Modified-Date". It seems that "Last-Modified" is the
correct header name according to the rfc: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

Line 274 of wsgiutils.py...
last_modified_date = time.strftime('%w, %d %b %Y %H:%M:%S
GMT', time.gmtime(stat.st_mtime)),
...should be...
last_modified = time.strftime('%w, %d %b %Y %H:%M:%S GMT',
time.gmtime(stat.st_mtime)),

Regards,
-Sam

Samuel Wan

unread,
Aug 27, 2010, 7:39:14 PM8/27/10
to Pesto
Also, in line 253 of wsgiutils.py, "stat.st_mtime" returns the
creation time rather than modification time on OSX, python 2.5.1, so a
"Last-Modified-Date" request header won't expire correctly. I found
"os.path.getmtime" to give the correct modification time instead.

-Sam

Oliver Cope

unread,
Aug 31, 2010, 6:26:34 AM8/31/10
to python...@googlegroups.com
On 28/08/2010 01:39, Samuel Wan wrote:
> Also, in line 253 of wsgiutils.py, "stat.st_mtime" returns the
> creation time rather than modification time on OSX, python 2.5.1, so a
> "Last-Modified-Date" request header won't expire correctly. I found
> "os.path.getmtime" to give the correct modification time instead.
>
Hi Sam,

Sorry I didn't get to your messages sooner, I've been away for my email
for the last few days. Thanks for the changes � I'll fix those headers
and the mtime problem and put a new release out.

Cheers,

Olly.

Oliver Cope

unread,
Sep 2, 2010, 1:25:00 PM9/2/10
to python...@googlegroups.com
On 31/08/2010 12:26, Oliver Cope wrote:
> On 28/08/2010 01:39, Samuel Wan wrote:
>> Also, in line 253 of wsgiutils.py, "stat.st_mtime" returns the
>> creation time rather than modification time on OSX, python 2.5.1, so a
>> "Last-Modified-Date" request header won't expire correctly. I found
>> "os.path.getmtime" to give the correct modification time instead.
>>
>
> Sorry I didn't get to your messages sooner, I've been away for my email
> for the last few days. Thanks for the changes � I'll fix those headers
> and the mtime problem and put a new release out.
>
Right, I've updated the serve_static_file function � are you able to try
this version on OSX and let me know if it fixes the problems you're having?

http://darcs.redgecko.org/pesto/dist/pesto-19dev.tar.gz

If it looks OK then I'll put out an official PyPI release.

Olly.


Samuel Wan

unread,
Aug 31, 2010, 11:52:06 AM8/31/10
to python...@googlegroups.com
Thanks a lot, Olly!

On Tue, Aug 31, 2010 at 3:26 AM, Oliver Cope <oli...@redgecko.org> wrote:
> On 28/08/2010 01:39, Samuel Wan wrote:
>>
>> Also, in line 253 of wsgiutils.py, "stat.st_mtime" returns the
>> creation time rather than modification time on OSX, python 2.5.1, so a
>> "Last-Modified-Date" request header won't expire correctly. I found
>> "os.path.getmtime" to give the correct modification time instead.
>>
> Hi Sam,
>
> Sorry I didn't get to your messages sooner, I've been away for my email for

> the last few days. Thanks for the changes – I'll fix those headers and the


> mtime problem and put a new release out.
>
> Cheers,
>
> Olly.
>

> --
> You received this message because you are subscribed to the Google Groups
> "Pesto" group.
> To post to this group, send email to python...@googlegroups.com.
> To unsubscribe from this group, send email to
> python-pesto...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/python-pesto?hl=en.
>
>

Samuel Wan

unread,
Sep 4, 2010, 12:34:58 PM9/4/10
to python...@googlegroups.com
I'm not very experienced with Pesto, but it seems a newly required
MutableMapping class isn't included in my version of python. Here's
the output I got when importing the python module from prompt:

samwan:~/temp $ tar -xzvf pesto-19dev.tar.gz
pesto-19dev/
pesto-19dev/doc/
pesto-19dev/pesto/
pesto-19dev/pesto.egg-info/
pesto-19dev/tests/
pesto-19dev/AUTHORS.txt
pesto-19dev/CHANGELOG.txt
pesto-19dev/FAQ.txt
pesto-19dev/INSTALL.txt
pesto-19dev/LICENSE.txt
pesto-19dev/MANIFEST.in
pesto-19dev/NEWS.txt
pesto-19dev/README.txt
pesto-19dev/THANKS.txt
pesto-19dev/TODO.txt
pesto-19dev/setup.py
pesto-19dev/PKG-INFO
pesto-19dev/setup.cfg
pesto-19dev/tests/form_data.py
pesto-19dev/tests/test_caching.py
pesto-19dev/tests/test_dispatcher.py
pesto-19dev/tests/test_httputils.py
pesto-19dev/tests/test_lru.py
pesto-19dev/tests/test_session.py
pesto-19dev/tests/test_utils.py
pesto-19dev/tests/test_web.py
pesto-19dev/tests/test_wsgiutils.py
pesto-19dev/pesto.egg-info/PKG-INFO
pesto-19dev/pesto.egg-info/SOURCES.txt
pesto-19dev/pesto.egg-info/dependency_links.txt
pesto-19dev/pesto.egg-info/not-zip-safe
pesto-19dev/pesto.egg-info/top_level.txt
pesto-19dev/pesto/session/
pesto-19dev/pesto/__init__.py
pesto-19dev/pesto/caching.py
pesto-19dev/pesto/cookie.py
pesto-19dev/pesto/core.py
pesto-19dev/pesto/dispatch.py
pesto-19dev/pesto/httputils.py
pesto-19dev/pesto/lrucache.py
pesto-19dev/pesto/request.py
pesto-19dev/pesto/response.py
pesto-19dev/pesto/testing.py
pesto-19dev/pesto/utils.py
pesto-19dev/pesto/wsgiutils.py
pesto-19dev/pesto/session/__init__.py
pesto-19dev/pesto/session/base.py
pesto-19dev/pesto/session/filesessionmanager.py
pesto-19dev/pesto/session/memorysessionmanager.py
pesto-19dev/doc/Makefile
pesto-19dev/doc/caching.rst
pesto-19dev/doc/conf.py
pesto-19dev/doc/cookies.rst
pesto-19dev/doc/dispatch.rst
pesto-19dev/doc/getting_started.rst
pesto-19dev/doc/index.rst
pesto-19dev/doc/request.rst
pesto-19dev/doc/response.rst
pesto-19dev/doc/session.rst
pesto-19dev/doc/utils.rst
pesto-19dev/doc/wsgiutils.rst
samwan:~/temp $ cd pesto-19dev
samwan:~/temp/pesto-19dev $ python
Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pesto
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pesto/__init__.py", line 39, in <module>
from pesto.core import *
File "pesto/core.py", line 17, in <module>
from pesto import response
File "pesto/response.py", line 877, in <module>
from pesto.wsgiutils import StartResponseWrapper, ClosingIterator
File "pesto/wsgiutils.py", line 48, in <module>
from pesto.utils import MultiDict
File "pesto/utils.py", line 11, in <module>
from collections import deque, MutableMapping
ImportError: cannot import name MutableMapping
>>>

Oliver Cope

unread,
Sep 7, 2010, 6:45:08 AM9/7/10
to python...@googlegroups.com

On 04/09/2010 18:34, Samuel Wan wrote:
> I'm not very experienced with Pesto, but it seems a newly required
> MutableMapping class isn't included in my version of python. Here's
> the output I got when importing the python module from prompt:

You're right, it looks like MutableMapping isn't available in Python 2.5
� I'll see what I can do to make the code backwards compatible.

Cheers,

Olly.

Reply all
Reply to author
Forward
0 new messages