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

Graham Dumpleton graham.dumpleton at gmail.com
Thu Jun 28 18:44:29 EDT 2007


On 29/06/07, Aaron Robinson <aaron.robinson at mojoworld.com> wrote:
>
>
>
>
> 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?

Can't be done.

I'm a bit busy to respond in detail on this at the moment, but do a
search through the mailing list archives using the search box on
www.modpython.org for 'publisher PSP'. This should pick up messages
which talk about using PSP from publisher, thus giving you more
control. There has also been past discussions on how to make PSP
output to a string so one can process output like you want. Look for
'PSP request wrapper'.

Graham

> 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.
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>
>


More information about the Mod_python mailing list