on master help sign in
Change Http2Application to return trailers
commitdf285cf3cd464bab8142d2430d47cea09a4504ae authorAndrew Pritchard <awpr@google.com> dateWed 29 Jul 2015, 21:25 (11 years ago) parent8273bed
3 files changed+12−10
wai/Network/Wai/HTTP2.hs+2−2 warp/Network/Wai/Handler/Warp/HTTP2.hs+4−1 warp/Network/Wai/Handler/Warp/HTTP2/Worker.hs+6−7
wai/Network/Wai/HTTP2.hs+2−2
@@ -5,11 +5,11 @@ module Network.Wai.HTTP2
55
66import qualified Network.HTTP.Types as H
77
8−import Network.Wai.Internal (Request, Response, ResponseReceived)
8+import Network.Wai.Internal (Request, Response)
99
1010-- | Headers sent after the end of a data stream, as defined by section 4.1.2 of
1111-- the HTTP\/1.1 spec (RFC 7230), and section 8.1 of the HTTP\/2 spec.
1212type Trailers = H.ResponseHeaders
1313
1414-- | The HTTP\/2-aware equivalent of 'Network.Wai.Application'.
15−type Http2Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived
15+type Http2Application = Request -> (Response -> IO ()) -> IO Trailers
warp/Network/Wai/Handler/Warp/HTTP2.hs+4−1
@@ -7,6 +7,7 @@ module Network.Wai.Handler.Warp.HTTP2
77 , promoteApplication
88 ) where
99
10+import Control.Applicative ((<$))
1011import Control.Concurrent (forkIO, killThread)
1112import qualified Control.Exception as E
1213import Control.Monad (when, unless, replicateM_)
@@ -17,6 +18,7 @@ import Network.Socket (SockAddr)
1718
1819import Network.Wai (Application)
1920import Network.Wai.HTTP2 (Http2Application)
21+import Network.Wai.Internal (ResponseReceived(..))
2022import Network.Wai.Handler.Warp.HTTP2.EncodeFrame
2123import Network.Wai.Handler.Warp.HTTP2.Manager
2224import Network.Wai.Handler.Warp.HTTP2.Receiver
@@ -75,4 +77,5 @@ goaway Connection{..} etype debugmsg = connSendAll bytestream
7577-- | Promote a normal WAI 'Application' to an 'Http2Application' by ignoring
7678-- the HTTP/2-specific features.
7779promoteApplication :: Application -> Http2Application
78−promoteApplication app = app
80+promoteApplication app req respond = [] <$ app req respond'
81+ where respond' x = ResponseReceived <$ respond x
warp/Network/Wai/Handler/Warp/HTTP2/Worker.hs+6−7
@@ -30,15 +30,15 @@ import Network.Wai.Handler.Warp.IORef
3030import qualified Network.Wai.Handler.Warp.Response as R
3131import qualified Network.Wai.Handler.Warp.Settings as S
3232import qualified Network.Wai.Handler.Warp.Timeout as T
33−import Network.Wai.Internal (Response(..), ResponseReceived(..), ResponseReceived(..))
33+import Network.Wai.Internal (Response(..))
3434
3535----------------------------------------------------------------
3636
37−-- | The wai definition is @type Http2Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived@.
38−-- This type implements the second argument @Response -> IO ResponseReceived@
37+-- | The wai definition is @type Http2Application = Request -> (Response -> IO ()) -> IO Trailers@.
38+-- This type implements the second argument @Response -> IO ()@
3939-- with extra arguments.
4040type Responder = ThreadContinue -> T.Handle -> Stream -> Request ->
41− TBQueue Sequence -> Response -> IO ResponseReceived
41+ TBQueue Sequence -> Response -> IO ()
4242
4343-- | This function is passed to workers.
4444-- They also pass 'Response's from 'Http2Application's to this function.
@@ -74,7 +74,6 @@ response Context{outputQ} mgr tconf th strm req sq rsp = do
7474 && R.hasBody (responseStatus rsp)
7575 out = OResponse strm rsp (Oneshot hasBody)
7676 enqueueOrSpawnTemporaryWaiter strm outputQ out
77− return ResponseReceived
7877
7978data Break = Break deriving (Show, Typeable)
8079
@@ -102,8 +101,8 @@ worker ctx@Context{inputQ,outputQ} set tm app responder = do
102101 T.tickle th
103102 app req $ responder tcont th strm req sq
104103 cont1 <- case ex of
105− Right ResponseReceived -> do
106− atomically $ writeTBQueue sq $ SFinish []
104+ Right trailers -> do
105+ atomically $ writeTBQueue sq $ SFinish trailers
107106 return True
108107 Left e@(SomeException _)
109108 | Just Break <- E.fromException e -> do