@@ -35,6 +35,8 @@ module Network.Wai.Handler.WarpTLS (
3535 -- * Runner
3636 , runTLS
3737 , runTLSSocket
38+ , runHttp2TLS
39+ , runHttp2TLSSocket
3840 -- * Exception
3941 , WarpTLSException (..)
4042 ) where
@@ -57,6 +59,7 @@ import Network.Socket.ByteString (sendAll)
5759import qualified Network.TLS as TLS
5860import qualified Network.TLS.Extra as TLSExtra
5961import Network.Wai (Application)
62+import Network.Wai.HTTP2 (Http2Application)
6063import Network.Wai.Handler.Warp
6164import Network.Wai.Handler.Warp.Internal
6265import System.IO.Error (isEOFError)
@@ -217,21 +220,38 @@ tlsSettingsChainMemory cert chainCerts key = defaultTlsSettings
217220
218221----------------------------------------------------------------
219222
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
220226
221227-- | Running 'Application' with 'TLSSettings' and 'Settings'.
222228runTLS :: TLSSettings -> Settings -> Application -> IO ()
223−runTLS tset set app = withSocketsDo $
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 ()
235+runServeTLS tset set serve = withSocketsDo $
224236 bracket
225237 (bindPortTCP (getPort set) (getHost set))
226238 sClose
227− (\sock -> runTLSSocket tset set sock app)
239+ (\sock -> runServeTLSSocket tset set sock serve)
228240
229241----------------------------------------------------------------
230242
231243-- | Running 'Application' with 'TLSSettings' and 'Settings' using
232244-- specified 'Socket'.
233245runTLSSocket :: TLSSettings -> Settings -> Socket -> Application -> IO ()
234−runTLSSocket tlsset@TLSSettings{..} set sock app = do
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 ()
254+runServeTLSSocket tlsset@TLSSettings{..} set sock serve = do
235255 credential <- case (certMemory, keyMemory) of
236256 (Nothing, Nothing) ->
237257 either error id <$>
@@ -241,11 +261,11 @@ runTLSSocket tlsset@TLSSettings{..} set sock app = do
241261 key <- maybe (S.readFile keyFile) return mkey
242262 either error return $
243263 TLS.credentialLoadX509ChainFromMemory cert chainCertsMemory key
244− runTLSSocket' tlsset set credential sock app
264+ runServeTLSSocket' tlsset set credential sock serve
245265
246−runTLSSocket' :: TLSSettings -> Settings -> TLS.Credential -> Socket -> Application -> IO ()
247−runTLSSocket' tlsset@TLSSettings{..} set credential sock app =
248− runSettingsConnectionMakerSecure set get app
266+runServeTLSSocket' :: TLSSettings -> Settings -> TLS.Credential -> Socket -> ServeConnection -> IO ()
267+runServeTLSSocket' tlsset@TLSSettings{..} set credential sock serve =
268+ runServeSettingsConnectionMakerSecure set get serve
249269 where
250270 get = getter tlsset sock params
251271 params = TLS.ServerParams {