[web-devel] Raw POST data
michael at snoyman.com
Tue May 31 05:11:08 CEST 2011
On Tue, May 31, 2011 at 5:23 AM, Jeremy Hughes <jedahu at gmail.com> wrote:
> Hi again,
> I can't find a means to access raw POST data. Both Network.Wai.Request
> and Yesod.Request.Request appear to only contain pre-parsed values.
> What am I missing?
There's an example in the haskell-web-rosetta repo of getting the
raw content of a request. (Next bit is slightly complicated.) The idea
is that a Handler is in fact a monad transformer on top of an
Iteratee. An Iteratee is a streaming data consumer, which allows us to
parse the request body in constant space. The "consume" function used
here turns that stream into a (strict) list of bytestrings, i.e.,
reads them all into memory. The use of lift is to deal with the fact
that Handler is a monad transformer.
So the simplest way to read the request body is the one shown in that
example. But depending on what you want to do, you could also use a
streaming approach via enumerators and thereby not read the entire
request body into memory. For example, with JSON, you could use
aeson and attoparsec-enumerator. But that requires a bit more
What exactly do you want to do with the raw request body?
More information about the web-devel