@@ -35,6 +35,8 @@ module Network.Wai.Handler.WarpTLS (
35 -- * Runner
35 -- * Runner
37 , runTLSSocket
37 , runTLSSocket
38 -- * Exception
40 -- * Exception
39 , WarpTLSException (..)
41 , WarpTLSException (..)
@@ -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
218----------------------------------------------------------------
221----------------------------------------------------------------
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
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
231+runHttp2TLS :: TLSSettings -> Settings -> Http2Application -> Application -> IO ()
232+runHttp2TLS tset set = runServeTLS tset set .: serveHttp2
234+runServeTLS :: TLSSettings -> Settings -> ServeConnection -> IO ()
223−runTLS tset set app = withSocketsDo $
235+runServeTLS tset set serve = withSocketsDo $
225 (bindPortTCP (getPort set) (getHost set))
237 (bindPortTCP (getPort set) (getHost set))
227− (\sock -> runTLSSocket tset set sock app)
239+ (\sock -> runServeTLSSocket tset set sock serve)
229----------------------------------------------------------------
241----------------------------------------------------------------
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
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
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
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
250 get = getter tlsset sock params
270 get = getter tlsset sock params
251 params = TLS.ServerParams {
271 params = TLS.ServerParams {