How do I copy wsgi.input if I want to process POST data more than once?

python, wsgi

Solution

Go have a look at WebOb package. It provides functionality that allows one to designate that wsgi.input should be made seekable. This has the effect of allowing you to rewind the input stream such that content can be replayed through different handler. Even if you don't use WebOb, the way it does this should be instructive as would trust Ian to have done this in an appropriate way. For search results in documentation go here.

Problem

In WSGI, post data is consumed by reading the file-like object `environ['wsgi.input']`. If a second element in the stack also wants to read post data it may hang the program by reading when there's nothing more to read. How should I copy the POST data so it can be processed multiple times?

Original source