[英]Haskell wai middleware - how to run application if 404 is returned from the first application?
I'm trying to 'join' two wai Application
s together.我正在尝试将两个 wai
Application
一起“加入”。 Essentially the first app will either serve a 404 Not found response or a response that is not a 404 Not found response .本质上,第一个应用程序将提供404 Not found 响应或不是404 Not found 响应的响应。 I'd like to add a second application that will attempt to process the request if the first case (first application returns a 404 ) is present.
我想添加第二个应用程序,如果第一种情况(第一个应用程序返回404 )存在,它将尝试处理请求。
However looking at the type of Application
:但是查看
Application
的类型:
type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived
It's not clear how to inspect the response?不清楚如何检查响应? As wouldn't I just end up with
ResponseRecived
as the end result - which does not seem to contain any response code.我不会只是以
ResponseRecived
作为最终结果 - 它似乎不包含任何响应代码。 As seen below:如下图所示:
xyzMiddle :: (Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived) ->
(Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived)
xyzMiddle app req respond = do
zzz <- (app req respond)
pure zzz
How could I implement this?我怎么能实现这个? And or, what am I failing to understand in the above?
或者,我在上面没有理解什么?
I overlooked this (Response -> IO ResponseReceived)
as that is in the IO
context - this is where we can run the second application.我忽略了这一点
(Response -> IO ResponseReceived)
,因为它在IO
上下文中 - 这是我们可以运行第二个应用程序的地方。 Which means, to inspect the Response
we can do something like:这意味着,要检查
Response
,我们可以执行以下操作:
xyzMiddle :: (Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived) ->
Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived
xyzMiddle app req respond = app req (\r -> do
print $ show $ responseStatus r
respond r)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.