[mod_python] Inspect request body before handing it over to mod_proxy

Graham Dumpleton graham.dumpleton at gmail.com
Sun May 27 19:52:36 EDT 2007

On 28/05/07, Jeremy Allen <mod_python at jez.net.nz> wrote:
> Hi,
> I'm using apache 2.2 with mod_proxy functioning as a reverse proxy.
> I was hoping to use mod_python to inspect the body of the http request
> before it gets handled by mod_proxy.
> I can happily make a Python*Handler which will receive the request before
> mod_proxy.
> I can inspect and change headers before handing it off to mod_proxy but as
> soon as I touch the body of the request things become trickier.
> Request.read() will give me the body of the request but doing so consumes
> the read characters from the body , thus passing on nothing down to
> mod_proxy.
> Am I right in thinking that I cannot merely observe the body of a request, I
> have to consume it?
> Also am I right in thinking that there is no way I can modify the body of a
> request before it gets handed down the request processing chain? (so I could
> read it then perhaps write it back to the request)
> I have also tried using a filter instead of a handler but I'm not sure if it
> is possible to trigger a server response like HTTP_FORBIDDEN from a filter.

To inspect/change the content you can only use an input filter. Do
note though that if you are changing the length of the content, that
will invalidate the incoming Content-Length header which can mean not
all your content may be sent through by mod_proxy if the new content
length is greater.

As to returning a HTTP_FORBIDDEN, is that based on the contents or the
headers. If headers, use a fixup handler. If content, I'm not sure at
the moment what you can do.

BTW, what are you proxying through to and what is the nature of the
changes being made to the content?


More information about the Mod_python mailing list