Haskell wai 中间件 - 如果第一个应用程序返回 404,如何 运行 应用程序?
Haskell wai middleware - how to run application if 404 is returned from the first application?
我正在尝试 'join' 两个 wai Application
在一起。本质上,第一个应用程序将提供 404 未找到响应 或不是 404 未找到响应 的响应。我想添加第二个应用程序,如果存在第一个案例(第一个应用程序 returns a 404),它将尝试处理请求。
但是查看 Application
的类型:
type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived
不清楚如何检查响应?我不会以 ResponseRecived
作为最终结果 - 它似乎不包含任何响应代码。如下所示:
xyzMiddle :: (Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived) ->
(Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived)
xyzMiddle app req respond = do
zzz <- (app req respond)
pure zzz
我该如何实现?或者,我在上面有什么不明白的地方?
我忽略了这个 (Response -> IO ResponseReceived)
,因为它在 IO
上下文中 - 这是我们可以 运行 第二个应用程序的地方。这意味着,要检查 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)
我正在尝试 'join' 两个 wai Application
在一起。本质上,第一个应用程序将提供 404 未找到响应 或不是 404 未找到响应 的响应。我想添加第二个应用程序,如果存在第一个案例(第一个应用程序 returns a 404),它将尝试处理请求。
但是查看 Application
的类型:
type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived
不清楚如何检查响应?我不会以 ResponseRecived
作为最终结果 - 它似乎不包含任何响应代码。如下所示:
xyzMiddle :: (Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived) ->
(Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived)
xyzMiddle app req respond = do
zzz <- (app req respond)
pure zzz
我该如何实现?或者,我在上面有什么不明白的地方?
我忽略了这个 (Response -> IO ResponseReceived)
,因为它在 IO
上下文中 - 这是我们可以 运行 第二个应用程序的地方。这意味着,要检查 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)