[web-devel] Upgrade to Happstack 6 - request bodies

Sebastiaan Visser haskell at fvisser.nl
Wed Jul 27 11:46:57 CEST 2011

Hello all,

We have some problems upgrading one of our server applications to Happstack 6, lots of things related to request bodies and request parameters have changed. Unfortunately, the new situation doesn't seem that straightforward to me.

In the previous version of Happstack we were able to access the request body directly using the `rqBody` function. In the new situation we have to first decode the body using `decodeBody` and than access it by reading from an MVar. The utility functions accessing this variables ensure the body is only request once, all consecutive calls will error.

We're pretty sure we're accessing the body only once and after decoding it, but we still get the following error: "askRqEnv failed because the request body has not been decoded yet. Try using 'decodeBody'." This happens when accessing the cookie using 'readCookieValue'. Isn't strange that accessing the cookie value uses the request body at all?

So the pattern we use is:

>   do decodeBody (defaultBodyPolicy "/tmp/" (10 * 1024 * 1024) (10 * 1024 * 1024) (1024 * 1024))
>      liftIO (print 1)
>      c <- lookCookieValue "tid"
>      liftIO (print 2)
>      b <- takeRequestBody
>      ...

And the result is:

>   1
>   askRqEnv failed because the request body has not been decoded yet. Try using 'decodeBody'.
(this happens using happstack-server-6.0.3, in 6.1.6 the same error string is sent to the client)

And then it stops, the handler crashes and the request fails. The migration guide[1] tells me "To simulate the old behavior, simple call decodeBody in your top-level handler for every request.", but this is clearly not enough.

Anyone knows how to fix this in the correct way? I cannot help to think it is a bit strange that it takes me so much time to convince a web framework to hand me over the request body. This should be easy stuff right?


[1] http://code.google.com/p/happstack/wiki/Happstack6Migration

More information about the web-devel mailing list