on master help sign in
Support HTTP/2 run functions in warp-tls
13892b9Andrew Pritchard
warp-tls/Network/Wai/Handler/WarpTLS.hs+27−7
@@ -35,6 +35,8 @@ module Network.Wai.Handler.WarpTLS (
35 -- * Runner
35 -- * Runner
36 , runTLS
36 , runTLS
37 , runTLSSocket
37 , runTLSSocket
38+ , runHttp2TLS
39+ , runHttp2TLSSocket
38 -- * Exception
40 -- * Exception
39 , WarpTLSException (..)
41 , WarpTLSException (..)
40 ) where
42 ) where
@@ -57,6 +59,7 @@ import Network.Socket.ByteString (sendAll)
57import qualified Network.TLS as TLS
59import qualified Network.TLS as TLS
58import qualified Network.TLS.Extra as TLSExtra
60import qualified Network.TLS.Extra as TLSExtra
59import Network.Wai (Application)
61import Network.Wai (Application)
62+import Network.Wai.HTTP2 (Http2Application)
60import Network.Wai.Handler.Warp
63import Network.Wai.Handler.Warp
61import Network.Wai.Handler.Warp.Internal
64import Network.Wai.Handler.Warp.Internal
62import System.IO.Error (isEOFError)
65import System.IO.Error (isEOFError)
@@ -217,21 +220,38 @@ tlsSettingsChainMemory cert chainCerts key = defaultTlsSettings
217
220
218----------------------------------------------------------------
221----------------------------------------------------------------
219
222
223+-- Composition over two arguments at once; used for runHttp2\*.
224+(.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
225+f .: g = curry $ f . uncurry g
220
226
221-- | Running 'Application' with 'TLSSettings' and 'Settings'.
227-- | Running 'Application' with 'TLSSettings' and 'Settings'.
222runTLS :: TLSSettings -> Settings -> Application -> IO ()
228runTLS :: TLSSettings -> Settings -> Application -> IO ()
229+runTLS tset set = runServeTLS tset set . serveDefault
230+
231+runHttp2TLS :: TLSSettings -> Settings -> Http2Application -> Application -> IO ()
232+runHttp2TLS tset set = runServeTLS tset set .: serveHttp2
233+
234+runServeTLS :: TLSSettings -> Settings -> ServeConnection -> IO ()
223−runTLS tset set app = withSocketsDo $
235+runServeTLS tset set serve = withSocketsDo $
224 bracket
236 bracket
225 (bindPortTCP (getPort set) (getHost set))
237 (bindPortTCP (getPort set) (getHost set))
226 sClose
238 sClose
227− (\sock -> runTLSSocket tset set sock app)
239+ (\sock -> runServeTLSSocket tset set sock serve)
228
240
229----------------------------------------------------------------
241----------------------------------------------------------------
230
242
231-- | Running 'Application' with 'TLSSettings' and 'Settings' using
243-- | Running 'Application' with 'TLSSettings' and 'Settings' using
232-- specified 'Socket'.
244-- specified 'Socket'.
233runTLSSocket :: TLSSettings -> Settings -> Socket -> Application -> IO ()
245runTLSSocket :: TLSSettings -> Settings -> Socket -> Application -> IO ()
246+runTLSSocket tset set sock = runServeTLSSocket tset set sock . serveDefault
247+
248+-- | Run an HTTP/2-aware server with 'TLSSettings' and 'Settings' using
249+-- specified 'Socket'.
250+runHttp2TLSSocket :: TLSSettings -> Settings -> Socket -> Http2Application -> Application -> IO ()
251+runHttp2TLSSocket tset set sock = runServeTLSSocket tset set sock .: serveHttp2
252+
253+runServeTLSSocket :: TLSSettings -> Settings -> Socket -> ServeConnection -> IO ()
234−runTLSSocket tlsset@TLSSettings{..} set sock app = do
254+runServeTLSSocket tlsset@TLSSettings{..} set sock serve = do
235 credential <- case (certMemory, keyMemory) of
255 credential <- case (certMemory, keyMemory) of
236 (Nothing, Nothing) ->
256 (Nothing, Nothing) ->
237 either error id <$>
257 either error id <$>
@@ -241,11 +261,11 @@ runTLSSocket tlsset@TLSSettings{..} set sock app = do
241 key <- maybe (S.readFile keyFile) return mkey
261 key <- maybe (S.readFile keyFile) return mkey
242 either error return $
262 either error return $
243 TLS.credentialLoadX509ChainFromMemory cert chainCertsMemory key
263 TLS.credentialLoadX509ChainFromMemory cert chainCertsMemory key
244− runTLSSocket' tlsset set credential sock app
264+ runServeTLSSocket' tlsset set credential sock serve
245
265
246−runTLSSocket' :: TLSSettings -> Settings -> TLS.Credential -> Socket -> Application -> IO ()
266+runServeTLSSocket' :: TLSSettings -> Settings -> TLS.Credential -> Socket -> ServeConnection -> IO ()
247−runTLSSocket' tlsset@TLSSettings{..} set credential sock app =
267+runServeTLSSocket' tlsset@TLSSettings{..} set credential sock serve =
248− runSettingsConnectionMakerSecure set get app
268+ runServeSettingsConnectionMakerSecure set get serve
249 where
269 where
250 get = getter tlsset sock params
270 get = getter tlsset sock params
251 params = TLS.ServerParams {
271 params = TLS.ServerParams {
warp/Network/Wai/Handler/Warp/Internal.hs+11
@@ -8,7 +8,18 @@ module Network.Wai.Handler.Warp.Internal (
8 , runSettingsConnection
8 , runSettingsConnection
9 , runSettingsConnectionMaker
9 , runSettingsConnectionMaker
10 , runSettingsConnectionMakerSecure
10 , runSettingsConnectionMakerSecure
11+ , runServe
12+ , runServeEnv
13+ , runServeSettings
14+ , runServeSettingsSocket
15+ , runServeSettingsConnection
16+ , runServeSettingsConnectionMaker
17+ , runServeSettingsConnectionMakerSecure
11 , Transport (..)
18 , Transport (..)
19+ -- * ServeConnection
20+ , ServeConnection
21+ , serveDefault
22+ , serveHttp2
12 -- * Connection
23 -- * Connection
13 , Connection (..)
24 , Connection (..)
14 , socketConnection
25 , socketConnection