I would like to be able to use the content of the body of a request to be used as part of a cache key.
My current code looks like:
caching app req respond =
-- Request Body is consumed here
cacheKey <- strictRequestBody req
-- the req object is no more usable as body was consumed
maybe (app req (addToCacheAndRespond cacheKey))
(sendResponse . responseFromCachedValue)
(lookup cacheKey cacheContainer)
I don't see any solution here. How could I either copy the request or generate another request from the cacheKey and the req object?
Or event better is there another better solution?
As bonus point, could someone point me the rationale from changing the type of Wai Application from Request -> IO Response
to Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived
.