on master help sign in
Add pushed streams to the HTTP/2 application
commit47fc3fe173b019074a705d61296f68bfaf27156e authorAndrew Pritchard <awpr@google.com> dateThu 30 Jul 2015, 21:40 (11 years ago) parent8574d57
3 files changed+18−7
wai/Network/Wai/HTTP2.hs+15−4 warp/Network/Wai/Handler/Warp/HTTP2.hs+1−1 warp/Network/Wai/Handler/Warp/HTTP2/Worker.hs+2−2
wai/Network/Wai/HTTP2.hs+15−4
@@ -1,8 +1,9 @@
1−{-# LANGUAGE RankNTypes #-}
1+{-# LANGUAGE EmptyCase, EmptyDataDecls, RankNTypes #-}
22module Network.Wai.HTTP2
33 ( Http2Application
44 , Response
55 , Trailers
6+ , absurd
67 , responseStatus
78 , responseStream
89 , responseHeaders
@@ -17,9 +18,19 @@ import qualified Network.Wai.Internal as H1 (Request)
1718-- the HTTP\/1.1 spec (RFC 7230), and section 8.1 of the HTTP\/2 spec.
1819type Trailers = H.ResponseHeaders
1920
20−-- | The type of an HTTP\/2 request.
21−-- TODO(awpr): specialize this for HTTP\/2.
22−type Request = H1.Request
21+-- | The synthesized request and headers of a pushed stream.
22+-- TODO(awpr): implement for real.
23+data PushPromise
24+
25+-- 'PushPromise' is currently uninhabited, which proves the caller cannot use
26+-- 'pushPromise'. This discharges the obligation to implement any function
27+-- taking a 'PushPromise'.
28+absurd :: PushPromise -> a
29+absurd p = case p of {}
30+
31+-- | The type of an HTTP\/2 request: a normal HTTP request and an action to
32+-- push streams associated with this request.
33+type Request = (H1.Request, PushPromise -> Responder -> IO ())
2334
2435-- | The HTTP\/2-aware equivalent of 'Network.Wai.Application'.
2536type Http2Application = Request -> Responder
warp/Network/Wai/Handler/Warp/HTTP2.hs+1−1
@@ -77,7 +77,7 @@ goaway Connection{..} etype debugmsg = connSendAll bytestream
7777-- | Promote a normal WAI 'Application' to an 'Http2Application' by ignoring
7878-- the HTTP/2-specific features.
7979promoteApplication :: Application -> Http2Application
80−promoteApplication app req respond = [] <$ app req respond'
80+promoteApplication app (req, _) respond = [] <$ app req respond'
8181 where
8282 respond' r = ResponseReceived <$ (withBody $ \b -> respond (s, h, b))
8383 where (s, h, withBody) = responseToStream r
warp/Network/Wai/Handler/Warp/HTTP2/Worker.hs+2−2
@@ -21,7 +21,7 @@ import Control.Monad (void, when)
2121import Data.Typeable
2222import Network.HTTP2
2323import Network.HTTP2.Priority
24−import Network.Wai.HTTP2 (Http2Application, Response)
24+import Network.Wai.HTTP2 (Http2Application, Response, absurd)
2525import Network.Wai hiding (Response, responseStatus)
2626import Network.Wai.Handler.Warp.HTTP2.EncodeFrame
2727import Network.Wai.Handler.Warp.HTTP2.Manager
@@ -94,7 +94,7 @@ worker ctx@Context{inputQ,outputQ} set tm app responder = do
9494 setStreamInfo sinfo strm req
9595 T.resume th
9696 T.tickle th
97− app req $ responder tcont th strm sq
97+ app (req, flip (const absurd)) $ responder tcont th strm sq
9898 cont1 <- case ex of
9999 Right trailers -> do
100100 atomically $ writeTBQueue sq $ SFinish trailers