Search code examples
haskellyesodconduithttp-conduit

How does one pipe `rawRequestBody` into `requestBodySource`?


Yesod has rawRequestBody with the following type signature:

rawRequestBody :: MonadHandler m => Source m ByteString

And http-conduit has this function that converts a source into a RequestBody:

requestBodySource :: Int64 -> Source (ResourceT IO) ByteString -> RequestBody

I want to be able to stream the rawRequestBody to an S3 object by converting it into a RequestBody inside a handler, ResourceT IO ~ MonadHandler doesn't compute and I can't seem to do MonadHandler m => m -> ResourceT IO

I've tried:

transPipe - if we get Source Handler ByteString from rawRequestBody it seems like the only way to get at the ByteString is to consume it, i.e

transPipe ??? rawRequestBody :: Source (ResourceT IO) ByteString

handlerToIO - however it seems like the request body is cleared so there won't be any data available

Please help :)


Solution

  • The function waiRequest will give you back the WAI Request value. You can use sourceRequestBody to get a Source from that.