[mod_python] meets_conditions does not seem to work

Graham Dumpleton grahamd at dscpl.com.au
Tue Nov 21 22:27:11 EST 2006

sliderw hotmail wrote ..
> I followed the documentation of meets_conditions and wrote the following
> handler, but it doesn't work. 200 OK is always returned, never 304 Not
> Modified.
> def handler(req):
>     req.headers_out['ETag'] = '"12345"'
>     req.headers_out['Last-Modified'] = 'Wed, 22 Nov 2006 01:00:00 GMT'
>     req.headers_out['Expires'] = 'Fri, 13 Feb 2009 01:00:00 GMT'
>     status = req.meets_conditions()
>     if status != apache.OK:
>         return status
>     req.set_content_length(5)
>     req.write('hello')
>     return apache.OK
> Versions used: Apache 2.2.2, mod_python 3.2.8
> Any idea?

What headers is your client sending which denote the condition that has to be
satisfied. Ie., what headers are in req.headers_in such as:


If your client isn't sending any conditions, how can there be anything to

Another issues is perhaps that 'Last-Modified' header isn't even consulted
anyway. Instead it looks at req.mtime attribute for when resource was last
modified. Getting this set to a sensible value in mod_python, because output is
generated dynamically, isn't that simple. In the version of mod_python you are
using it probably isn't even possible as there is no way to update req.mtime.

In mod_python 3.3, req.mtime is still read only, but req.set_last_modified() is
provided which allows req.mtime to be set from the mtime in req.finfo with
req.finfo being able to be updated by setting it to result of calling the
apache.stat() method with a file name. Problem is that in mod_python the mtime
may need to reflect changes across multiple files which comprise the source
code used to fulfil a request. Thus, in some respects, req.mtime should possibly
be directly modifiable to be of most use, but it isn't right now.

Anyway, having said all that, what are you expecting to happen and how
do you expect to be able to use req.meets_condition()?


More information about the Mod_python mailing list