on master help sign in
Allow Responder to decide whether to "catch" exceptions

If a Responder's TrailerFunc returns Nothing when given an exception, it will be re-raised; otherwise it will be "caught".

commit8c8359f53fbcdacd91dbf36bbf47948c99153b84 authorAndrew Pritchard <awpr@google.com> dateWed 9 Sep 2015, 22:34 (11 years ago) parent211c75c
2 files changed+5−3
wai/Network/Wai/HTTP2.hs+1−1 warp/Network/Wai/Handler/Warp/HTTP2/Worker.hs+4−2
wai/Network/Wai/HTTP2.hs+1−1
@@ -107,7 +107,7 @@ type Body a = BodyOf Chunk a
107107type BodyOf c a = (c -> IO ()) -> IO () -> IO a
108108
109109-- | Create trailers based on the result of a stream body.
110−type TrailerFunc a = Either SomeException a -> Trailers -- TODO IO?
110+type TrailerFunc a = Either SomeException a -> Maybe Trailers -- TODO IO?
111111
112112-- | Given to 'Responders'; provide a status, headers, a stream body, and a way
113113-- to produce trailers, and we'll give you a token proving you called the
warp/Network/Wai/Handler/Warp/HTTP2/Worker.hs+4−2
@@ -18,6 +18,7 @@ import Control.Concurrent.STM
1818import Control.Exception (Exception, SomeException(..), AsyncException(..), throwIO)
1919import qualified Control.Exception as E
2020import Control.Monad (void, when)
21+import Data.Maybe (fromMaybe)
2122import Data.Typeable
2223import qualified Network.HTTP.Types as H
2324import Network.HTTP2
@@ -93,8 +94,9 @@ runStream Context{outputQ} mkOutput tickle strm s h trailers strmbdy = do
9394 -- Run the stream body, use its result to construct the trailers, and
9495 -- re-raise any Exception so it will still be handled later.
9596 x <- E.try $ strmbdy write flush
96− atomically $ writeTBQueue sq $ SFinish $ trailers x
97− either throwIO (void . return) x
97+ case (x, trailers x) of
98+ (Left exc, Nothing) -> throwIO exc
99+ (_, mts) -> atomically $ writeTBQueue sq $ SFinish $ fromMaybe [] mts
98100
99101-- | Handle abnormal termination of a stream: mark it as closed, send a reset
100102-- frame, and call the user's 'settingsOnException' handler if applicable.