on master help sign in
Properly use exception response callback in HTTP2 stream responses.
commitc18590a7d4c31d6129e7a49102d3d3dbbe175038 authorIan Duncan <ian@iankduncan.com> dateFri 19 Apr 2019, 15:32 (7 years ago) parent1e2cc04
1 file changed+7−2
warp/Network/Wai/Handler/Warp/HTTP2/Worker.hs+7−2
warp/Network/Wai/Handler/Warp/HTTP2/Worker.hs+7−2
@@ -119,7 +119,7 @@ pushStream ctx@Context{http2settings,outputQ,streamTable}
119119-- They also pass 'Response's from 'Application's to this function.
120120-- This function enqueues commands for the HTTP/2 sender.
121121response :: S.Settings -> Context -> Manager -> Responder
122−response settings ctx@Context{outputQ} mgr ii reqvt tconf strm req rsp = case rsp of
122+response settings ctx@Context{outputQ} mgr ii reqvt tconf strm req rsp = E.handle (E.throwIO . ExceptionInsideResponseBody) $ case rsp of
123123 ResponseStream s0 hs0 strmbdy
124124 | noBody s0 -> responseNoBody s0 hs0
125125 | isHead -> responseNoBody s0 hs0
@@ -255,7 +255,12 @@ worker ctx@Context{inputQ,controlQ} set app responder tm = do
255255 return bs
256256 !vaultValue = Vault.insert pauseTimeoutKey (Timeout.pause th) $ vault req
257257 !req' = req { vault = vaultValue, requestBody = body' }
258− app req' $ responder ii' reqvt tcont strm req'
258+ mr <- E.try $ app req' $ responder ii' reqvt tcont strm req'
259+ case mr of
260+ Right ok -> return ok
261+ Left e@(SomeException _)
262+ | Just (ExceptionInsideResponseBody e') <- E.fromException e -> E.throwIO e'
263+ | otherwise -> responder ii' reqvt tcont strm req' (S.settingsOnExceptionResponse set e)
259264 cont1 <- case ex of
260265 Right ResponseReceived -> return True
261266 Left e@(SomeException _)