[mod_python] Checking a PSP-generated response before starting to send it..?

Aaron Robinson aaron.robinson at mojoworld.com
Thu Jun 28 18:30:59 EDT 2007


For lack of any feedback on this, I've come up with 1/2 a solution
(possibly), but would still very much appreciate *any* input..

 

I've written a output filter which read()'s all the input it gets, then
stores it in an attribute it creates on filter.req (and write()'s nothing),
then when it reads None (end of stream) it can compare the total page to the
last sent page and either write() the whole page (unmodified) or change the
'Last-Modified' date to the previous date + change the response code to a
304...  problem is that I don't know if it's possible for an output filter
to change the response code..

 

Any ideas on how to make an output filter change the response code, or
whether there are any holes in this plan - or preferably if there's a way to
avoid this completely?

 

Thanks,

Aaron.

 

  _____  

From: mod_python-bounces at modpython.org
[mailto:mod_python-bounces at modpython.org] On Behalf Of Aaron Robinson
Sent: Wednesday, 27 June 2007 11:28 p.m.
To: mod_python at modpython.org
Subject: [mod_python] Checking a PSP-generated response before starting to
send it..?

 

Hi all,

 

I'm running Apache 2.2.4 on Win32 with mod_python 3.3.1 and Python 2.5.1.

I'm completely new to Apache (and hence mod_python), but am reasonably
proficient with python itself.

 

I'm working on a web service where all content is generated on the fly, and
am wanting to use PSP to facilitate this.

Making as much use as possible of "304: Not Modified" is extremely important
to this project to reduce bandwidth, which is difficult as I have to
generate the content before I know whether it's different ("been modified")
from the last time I sent it or not..

 

I previously used a mechanism (not using Apache) where I would generate the
response, then take a hash of it and if it matched the hash of the last
response I sent, I would instead send a "304: Not Modified".

My problem is that when using PSP.run(), the response has already been sent
by the time it's finished being generated, so I have no opportunity to step
in and examine the response to see if sending a 304 is possible.

 

I'm needing an across-the-board mechanism for dealing with this - I thought
of serializing the "vars" dictionary before passing it in and taking a hash
of that for comparison, but this is hardly full-proof, as it would
(incorrectly) lead to responding with a 304 even with different "session"
information, or, in the slightly odd case that the PSP file made use of
random.random(), etc.

 

Just a thought: Is there a more general mechanism that can detect identical
content to a previous response on the way out and replace it with a 304?

 

Thanks in advance,

Aaron.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20070629/c0ebb402/attachment.html


More information about the Mod_python mailing list