【发布时间】:2015-12-01 13:28:04
【问题描述】:
我希望能够将请求正文的内容用作缓存键的一部分。
我当前的代码如下:
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)
我在这里没有看到任何解决方案。如何从 cacheKey 和 req 对象复制请求或生成另一个请求?
或者事件更好有没有其他更好的解决方案?
作为奖励,有人能指出将 Wai Application 类型从 Request -> IO Response 更改为 Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived 的理由吗?
【问题讨论】:
-
Michael Snoyman 在this blog article 中讨论了 WAI API 更改的一些原因。还有一个follow up。
-
谢谢!写我的中间件确实更难。
标签: haskell middleware haskell-wai