@@ -1,17 +1,20 @@
1−{-# LANGUAGE EmptyCase, EmptyDataDecls, RankNTypes #-}
1+{-# LANGUAGE OverloadedStrings, RankNTypes #-}
22module Network.Wai.HTTP2
33 ( Http2Application
4− , PushPromise
4+ , PushPromise(..)
55 , Responder
66 , Response
77 , Trailers
8− , absurd
98 , responseStatus
109 , responseStream
1110 , responseHeaders
11+ , promiseHeaders
1212 ) where
1313
14−import Blaze.ByteString.Builder (Builder)
14+import Data.ByteString (ByteString)
15+import qualified Data.ByteString.Lazy as L
16+
17+import Data.ByteString.Builder (Builder)
1518import qualified Network.HTTP.Types as H
1619
1720import qualified Network.Wai.Internal as H1 (Request)
@@ -21,14 +24,13 @@ import qualified Network.Wai.Internal as H1 (Request)
2124type Trailers = [H.Header]
2225
2326-- | The synthesized request and headers of a pushed stream.
24−-- TODO(awpr): implement for real.
25−data PushPromise
26−
27−-- 'PushPromise' is currently uninhabited, which proves the caller cannot use
28−-- 'pushPromise'. This discharges the obligation to implement any function
29−-- taking a 'PushPromise'.
30−absurd :: PushPromise -> a
31−absurd p = case p of {}
27+data PushPromise = PushPromise
28+ { promisedMethod :: H.Method
29+ , promisedPath :: ByteString
30+ , promisedAuthority :: ByteString
31+ , promisedScheme :: ByteString
32+ , promisedHeader :: H.RequestHeaders
33+ }
3234
3335-- | The type of an HTTP\/2 request: a normal HTTP request and an action to
3436-- push streams associated with this request.
@@ -51,3 +53,11 @@ responseHeaders (_, h, _) = h
5153
5254responseStream :: H.Status -> H.ResponseHeaders -> Body a -> Response a
5355responseStream = (,,)
56+
57+promiseHeaders :: PushPromise -> H.RequestHeaders
58+promiseHeaders p =
59+ [ (":method", promisedMethod p)
60+ , (":path", promisedPath p)
61+ , (":authority", promisedAuthority p)
62+ , (":scheme", promisedScheme p)
63+ ] ++ promisedHeader p