{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Network.HTTP2.TLS.Server (
run,
runWithSocket,
runH2C,
runH2CWithSocket,
Server,
HostName,
PortNumber,
runTLS,
runTLSWithSocket,
Settings,
defaultSettings,
settingsTimeout,
settingsSendBufferSize,
settingsSlowlorisSize,
settingsReadBufferSize,
settingsReadBufferLowerLimit,
settingsKeyLogger,
settingsNumberOfWorkers,
settingsConcurrentStreams,
settingsConnectionWindowSize,
settingsStreamWindowSize,
settingsSessionManager,
settingsEarlyDataSize,
settingsPingRateLimit,
settingsEmptyFrameRateLimit,
settingsSettingsRateLimit,
settingsRstRateLimit,
IOBackend,
send,
sendMany,
recv,
requestSock,
mySockAddr,
peerSockAddr,
runIO,
runIOH2C,
Stream,
ServerIO (..),
) where
import qualified Control.Exception as E
import Data.ByteString (ByteString)
import Network.HTTP2.Server (
Server,
connectionWindowSize,
defaultServerConfig,
emptyFrameRateLimit,
initialWindowSize,
maxConcurrentStreams,
pingRateLimit,
rstRateLimit,
settings,
settingsRateLimit,
)
import qualified Network.HTTP2.Server as H2Server
import Network.HTTP2.Server.Internal (ServerIO, Stream)
import qualified Network.HTTP2.Server.Internal as H2I
import Network.Run.TCP.Timeout
import Network.Socket (
HostName,
PortNumber,
Socket,
)
import Network.TLS hiding (HostName)
import qualified System.TimeManager as T
import Network.HTTP2.TLS.Config
import Network.HTTP2.TLS.IO
import Network.HTTP2.TLS.Server.Settings
import Network.HTTP2.TLS.Supported
runTLS
:: Settings
-> Credentials
-> HostName
-> PortNumber
-> ByteString
-> (T.Manager -> IOBackend -> IO a)
-> IO a
runTLS :: forall a.
Settings
-> Credentials
-> HostName
-> PortNumber
-> ByteString
-> (Manager -> IOBackend -> IO a)
-> IO a
runTLS Settings
settings Credentials
creds HostName
host PortNumber
port ByteString
alpn Manager -> IOBackend -> IO a
action =
Int -> Maybe HostName -> HostName -> TimeoutServer a -> IO a
forall a.
Int -> Maybe HostName -> HostName -> TimeoutServer a -> IO a
runTCPServer
(Settings -> Int
settingsTimeout Settings
settings)
(HostName -> Maybe HostName
forall a. a -> Maybe a
Just HostName
host)
(PortNumber -> HostName
forall a. Show a => a -> HostName
show PortNumber
port)
(TimeoutServer a -> IO a) -> TimeoutServer a -> IO a
forall a b. (a -> b) -> a -> b
$ \Manager
mgr Handle
th Socket
sock -> do
Backend
backend <- Settings -> Socket -> IO Backend
mkBackend Settings
settings Socket
sock
Context
ctx <- Backend -> ServerParams -> IO Context
forall (m :: * -> *) backend params.
(MonadIO m, HasBackend backend, TLSParams params) =>
backend -> params -> m Context
contextNew Backend
backend ServerParams
params
Context -> IO ()
forall (m :: * -> *). MonadIO m => Context -> m ()
handshake Context
ctx
IOBackend
iobackend <- Handle -> Settings -> IOBackend -> IOBackend
timeoutIOBackend Handle
th Settings
settings (IOBackend -> IOBackend) -> IO IOBackend -> IO IOBackend
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Context -> Socket -> IO IOBackend
tlsIOBackend Context
ctx Socket
sock
a
r <- Manager -> IOBackend -> IO a
action Manager
mgr IOBackend
iobackend
Context -> IO ()
forall (m :: * -> *). MonadIO m => Context -> m ()
bye Context
ctx
a -> IO a
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
r
where
params :: ServerParams
params = Settings -> Credentials -> ByteString -> ServerParams
getServerParams Settings
settings Credentials
creds ByteString
alpn
runTLSWithSocket
:: Settings
-> Credentials
-> Socket
-> ByteString
-> (T.Manager -> IOBackend -> IO a)
-> IO a
runTLSWithSocket :: forall a.
Settings
-> Credentials
-> Socket
-> ByteString
-> (Manager -> IOBackend -> IO a)
-> IO a
runTLSWithSocket Settings
settings Credentials
creds Socket
s ByteString
alpn Manager -> IOBackend -> IO a
action =
Int -> Socket -> TimeoutServer a -> IO a
forall a. Int -> Socket -> TimeoutServer a -> IO a
runTCPServerWithSocket
(Settings -> Int
settingsTimeout Settings
settings)
Socket
s
(TimeoutServer a -> IO a) -> TimeoutServer a -> IO a
forall a b. (a -> b) -> a -> b
$ \Manager
mgr Handle
th Socket
sock -> do
Backend
backend <- Settings -> Socket -> IO Backend
mkBackend Settings
settings Socket
sock
Context
ctx <- Backend -> ServerParams -> IO Context
forall (m :: * -> *) backend params.
(MonadIO m, HasBackend backend, TLSParams params) =>
backend -> params -> m Context
contextNew Backend
backend ServerParams
params
Context -> IO ()
forall (m :: * -> *). MonadIO m => Context -> m ()
handshake Context
ctx
IOBackend
iobackend <- Handle -> Settings -> IOBackend -> IOBackend
timeoutIOBackend Handle
th Settings
settings (IOBackend -> IOBackend) -> IO IOBackend -> IO IOBackend
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Context -> Socket -> IO IOBackend
tlsIOBackend Context
ctx Socket
sock
a
r <- Manager -> IOBackend -> IO a
action Manager
mgr IOBackend
iobackend
Context -> IO ()
forall (m :: * -> *). MonadIO m => Context -> m ()
bye Context
ctx
a -> IO a
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
r
where
params :: ServerParams
params = Settings -> Credentials -> ByteString -> ServerParams
getServerParams Settings
settings Credentials
creds ByteString
alpn
run :: Settings -> Credentials -> HostName -> PortNumber -> Server -> IO ()
run :: Settings
-> Credentials -> HostName -> PortNumber -> Server -> IO ()
run Settings
settings Credentials
creds HostName
host PortNumber
port Server
server =
Settings
-> Credentials
-> HostName
-> PortNumber
-> ByteString
-> (Manager -> IOBackend -> IO ())
-> IO ()
forall a.
Settings
-> Credentials
-> HostName
-> PortNumber
-> ByteString
-> (Manager -> IOBackend -> IO a)
-> IO a
runTLS Settings
settings Credentials
creds HostName
host PortNumber
port ByteString
"h2" ((Manager -> IOBackend -> IO ()) -> IO ())
-> (Manager -> IOBackend -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ Settings -> Server -> Manager -> IOBackend -> IO ()
run' Settings
settings Server
server
runWithSocket :: Settings -> Credentials -> Socket -> Server -> IO ()
runWithSocket :: Settings -> Credentials -> Socket -> Server -> IO ()
runWithSocket Settings
settings Credentials
creds Socket
s Server
server =
Settings
-> Credentials
-> Socket
-> ByteString
-> (Manager -> IOBackend -> IO ())
-> IO ()
forall a.
Settings
-> Credentials
-> Socket
-> ByteString
-> (Manager -> IOBackend -> IO a)
-> IO a
runTLSWithSocket Settings
settings Credentials
creds Socket
s ByteString
"h2" ((Manager -> IOBackend -> IO ()) -> IO ())
-> (Manager -> IOBackend -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ Settings -> Server -> Manager -> IOBackend -> IO ()
run' Settings
settings Server
server
runH2C :: Settings -> HostName -> PortNumber -> Server -> IO ()
runH2C :: Settings -> HostName -> PortNumber -> Server -> IO ()
runH2C settings :: Settings
settings@Settings{Int
SessionManager
HostName -> IO ()
settingsTimeout :: Settings -> Int
settingsSendBufferSize :: Settings -> Int
settingsSlowlorisSize :: Settings -> Int
settingsReadBufferSize :: Settings -> Int
settingsReadBufferLowerLimit :: Settings -> Int
settingsKeyLogger :: Settings -> HostName -> IO ()
settingsNumberOfWorkers :: Settings -> Int
settingsConcurrentStreams :: Settings -> Int
settingsConnectionWindowSize :: Settings -> Int
settingsStreamWindowSize :: Settings -> Int
settingsSessionManager :: Settings -> SessionManager
settingsEarlyDataSize :: Settings -> Int
settingsPingRateLimit :: Settings -> Int
settingsEmptyFrameRateLimit :: Settings -> Int
settingsSettingsRateLimit :: Settings -> Int
settingsRstRateLimit :: Settings -> Int
settingsTimeout :: Int
settingsSendBufferSize :: Int
settingsSlowlorisSize :: Int
settingsReadBufferSize :: Int
settingsReadBufferLowerLimit :: Int
settingsKeyLogger :: HostName -> IO ()
settingsNumberOfWorkers :: Int
settingsConcurrentStreams :: Int
settingsStreamWindowSize :: Int
settingsConnectionWindowSize :: Int
settingsSessionManager :: SessionManager
settingsEarlyDataSize :: Int
settingsPingRateLimit :: Int
settingsEmptyFrameRateLimit :: Int
settingsSettingsRateLimit :: Int
settingsRstRateLimit :: Int
..} HostName
host PortNumber
port Server
server =
Int -> Maybe HostName -> HostName -> TimeoutServer () -> IO ()
forall a.
Int -> Maybe HostName -> HostName -> TimeoutServer a -> IO a
runTCPServer
Int
settingsTimeout
(HostName -> Maybe HostName
forall a. a -> Maybe a
Just HostName
host)
(PortNumber -> HostName
forall a. Show a => a -> HostName
show PortNumber
port)
(TimeoutServer () -> IO ()) -> TimeoutServer () -> IO ()
forall a b. (a -> b) -> a -> b
$ \Manager
mgr Handle
th Socket
sock -> do
IOBackend
iobackend0 <- Settings -> Socket -> IO IOBackend
tcpIOBackend Settings
settings Socket
sock
let iobackend :: IOBackend
iobackend = Handle -> Settings -> IOBackend -> IOBackend
timeoutIOBackend Handle
th Settings
settings IOBackend
iobackend0
Settings -> Server -> Manager -> IOBackend -> IO ()
run' Settings
settings Server
server Manager
mgr IOBackend
iobackend
runH2CWithSocket :: Settings -> Socket -> Server -> IO ()
runH2CWithSocket :: Settings -> Socket -> Server -> IO ()
runH2CWithSocket settings :: Settings
settings@Settings{Int
SessionManager
HostName -> IO ()
settingsTimeout :: Settings -> Int
settingsSendBufferSize :: Settings -> Int
settingsSlowlorisSize :: Settings -> Int
settingsReadBufferSize :: Settings -> Int
settingsReadBufferLowerLimit :: Settings -> Int
settingsKeyLogger :: Settings -> HostName -> IO ()
settingsNumberOfWorkers :: Settings -> Int
settingsConcurrentStreams :: Settings -> Int
settingsConnectionWindowSize :: Settings -> Int
settingsStreamWindowSize :: Settings -> Int
settingsSessionManager :: Settings -> SessionManager
settingsEarlyDataSize :: Settings -> Int
settingsPingRateLimit :: Settings -> Int
settingsEmptyFrameRateLimit :: Settings -> Int
settingsSettingsRateLimit :: Settings -> Int
settingsRstRateLimit :: Settings -> Int
settingsTimeout :: Int
settingsSendBufferSize :: Int
settingsSlowlorisSize :: Int
settingsReadBufferSize :: Int
settingsReadBufferLowerLimit :: Int
settingsKeyLogger :: HostName -> IO ()
settingsNumberOfWorkers :: Int
settingsConcurrentStreams :: Int
settingsStreamWindowSize :: Int
settingsConnectionWindowSize :: Int
settingsSessionManager :: SessionManager
settingsEarlyDataSize :: Int
settingsPingRateLimit :: Int
settingsEmptyFrameRateLimit :: Int
settingsSettingsRateLimit :: Int
settingsRstRateLimit :: Int
..} Socket
s Server
server =
Int -> Socket -> TimeoutServer () -> IO ()
forall a. Int -> Socket -> TimeoutServer a -> IO a
runTCPServerWithSocket
Int
settingsTimeout
Socket
s
(TimeoutServer () -> IO ()) -> TimeoutServer () -> IO ()
forall a b. (a -> b) -> a -> b
$ \Manager
mgr Handle
th Socket
sock -> do
IOBackend
iobackend0 <- Settings -> Socket -> IO IOBackend
tcpIOBackend Settings
settings Socket
sock
let iobackend :: IOBackend
iobackend = Handle -> Settings -> IOBackend -> IOBackend
timeoutIOBackend Handle
th Settings
settings IOBackend
iobackend0
Settings -> Server -> Manager -> IOBackend -> IO ()
run' Settings
settings Server
server Manager
mgr IOBackend
iobackend
run' :: Settings -> Server -> T.Manager -> IOBackend -> IO ()
run' :: Settings -> Server -> Manager -> IOBackend -> IO ()
run' settings0 :: Settings
settings0@Settings{Int
SessionManager
HostName -> IO ()
settingsTimeout :: Settings -> Int
settingsSendBufferSize :: Settings -> Int
settingsSlowlorisSize :: Settings -> Int
settingsReadBufferSize :: Settings -> Int
settingsReadBufferLowerLimit :: Settings -> Int
settingsKeyLogger :: Settings -> HostName -> IO ()
settingsNumberOfWorkers :: Settings -> Int
settingsConcurrentStreams :: Settings -> Int
settingsConnectionWindowSize :: Settings -> Int
settingsStreamWindowSize :: Settings -> Int
settingsSessionManager :: Settings -> SessionManager
settingsEarlyDataSize :: Settings -> Int
settingsPingRateLimit :: Settings -> Int
settingsEmptyFrameRateLimit :: Settings -> Int
settingsSettingsRateLimit :: Settings -> Int
settingsRstRateLimit :: Settings -> Int
settingsTimeout :: Int
settingsSendBufferSize :: Int
settingsSlowlorisSize :: Int
settingsReadBufferSize :: Int
settingsReadBufferLowerLimit :: Int
settingsKeyLogger :: HostName -> IO ()
settingsNumberOfWorkers :: Int
settingsConcurrentStreams :: Int
settingsStreamWindowSize :: Int
settingsConnectionWindowSize :: Int
settingsSessionManager :: SessionManager
settingsEarlyDataSize :: Int
settingsPingRateLimit :: Int
settingsEmptyFrameRateLimit :: Int
settingsSettingsRateLimit :: Int
settingsRstRateLimit :: Int
..} Server
server Manager
mgr IOBackend{IO ByteString
SockAddr
Socket
[ByteString] -> IO ()
ByteString -> IO ()
send :: IOBackend -> ByteString -> IO ()
sendMany :: IOBackend -> [ByteString] -> IO ()
recv :: IOBackend -> IO ByteString
requestSock :: IOBackend -> Socket
mySockAddr :: IOBackend -> SockAddr
peerSockAddr :: IOBackend -> SockAddr
send :: ByteString -> IO ()
sendMany :: [ByteString] -> IO ()
recv :: IO ByteString
requestSock :: Socket
mySockAddr :: SockAddr
peerSockAddr :: SockAddr
..} =
IO Config -> (Config -> IO ()) -> (Config -> IO ()) -> IO ()
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
E.bracket
(Settings
-> Manager
-> (ByteString -> IO ())
-> IO ByteString
-> SockAddr
-> SockAddr
-> IO Config
allocConfigForServer Settings
settings0 Manager
mgr ByteString -> IO ()
send IO ByteString
recv SockAddr
mySockAddr SockAddr
peerSockAddr)
Config -> IO ()
freeConfigForServer
(\Config
conf -> ServerConfig -> Config -> Server -> IO ()
H2Server.run ServerConfig
sconf Config
conf Server
server)
where
sconf :: ServerConfig
sconf =
ServerConfig
defaultServerConfig
{ connectionWindowSize = settingsConnectionWindowSize
, settings =
(settings defaultServerConfig)
{ initialWindowSize = settingsStreamWindowSize
, maxConcurrentStreams = Just settingsConcurrentStreams
, pingRateLimit = settingsPingRateLimit
, emptyFrameRateLimit = settingsEmptyFrameRateLimit
, settingsRateLimit = settingsSettingsRateLimit
, rstRateLimit = settingsRstRateLimit
}
}
runIO
:: Settings
-> Credentials
-> Socket
-> (ServerIO Stream -> IO (IO ()))
-> IO ()
runIO :: Settings
-> Credentials
-> Socket
-> (ServerIO Stream -> IO (IO ()))
-> IO ()
runIO Settings
settings Credentials
creds Socket
s ServerIO Stream -> IO (IO ())
action =
Settings
-> Credentials
-> Socket
-> ByteString
-> (Manager -> IOBackend -> IO ())
-> IO ()
forall a.
Settings
-> Credentials
-> Socket
-> ByteString
-> (Manager -> IOBackend -> IO a)
-> IO a
runTLSWithSocket Settings
settings Credentials
creds Socket
s ByteString
"h2" ((Manager -> IOBackend -> IO ()) -> IO ())
-> (Manager -> IOBackend -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Manager
mgr IOBackend
iobackend ->
Settings
-> (ServerIO Stream -> IO (IO ())) -> Manager -> IOBackend -> IO ()
runIO' Settings
settings ServerIO Stream -> IO (IO ())
action Manager
mgr IOBackend
iobackend
runIO'
:: Settings -> (ServerIO Stream -> IO (IO ())) -> T.Manager -> IOBackend -> IO ()
runIO' :: Settings
-> (ServerIO Stream -> IO (IO ())) -> Manager -> IOBackend -> IO ()
runIO' settings0 :: Settings
settings0@Settings{Int
SessionManager
HostName -> IO ()
settingsTimeout :: Settings -> Int
settingsSendBufferSize :: Settings -> Int
settingsSlowlorisSize :: Settings -> Int
settingsReadBufferSize :: Settings -> Int
settingsReadBufferLowerLimit :: Settings -> Int
settingsKeyLogger :: Settings -> HostName -> IO ()
settingsNumberOfWorkers :: Settings -> Int
settingsConcurrentStreams :: Settings -> Int
settingsConnectionWindowSize :: Settings -> Int
settingsStreamWindowSize :: Settings -> Int
settingsSessionManager :: Settings -> SessionManager
settingsEarlyDataSize :: Settings -> Int
settingsPingRateLimit :: Settings -> Int
settingsEmptyFrameRateLimit :: Settings -> Int
settingsSettingsRateLimit :: Settings -> Int
settingsRstRateLimit :: Settings -> Int
settingsTimeout :: Int
settingsSendBufferSize :: Int
settingsSlowlorisSize :: Int
settingsReadBufferSize :: Int
settingsReadBufferLowerLimit :: Int
settingsKeyLogger :: HostName -> IO ()
settingsNumberOfWorkers :: Int
settingsConcurrentStreams :: Int
settingsStreamWindowSize :: Int
settingsConnectionWindowSize :: Int
settingsSessionManager :: SessionManager
settingsEarlyDataSize :: Int
settingsPingRateLimit :: Int
settingsEmptyFrameRateLimit :: Int
settingsSettingsRateLimit :: Int
settingsRstRateLimit :: Int
..} ServerIO Stream -> IO (IO ())
action Manager
mgr IOBackend{IO ByteString
SockAddr
Socket
[ByteString] -> IO ()
ByteString -> IO ()
send :: IOBackend -> ByteString -> IO ()
sendMany :: IOBackend -> [ByteString] -> IO ()
recv :: IOBackend -> IO ByteString
requestSock :: IOBackend -> Socket
mySockAddr :: IOBackend -> SockAddr
peerSockAddr :: IOBackend -> SockAddr
send :: ByteString -> IO ()
sendMany :: [ByteString] -> IO ()
recv :: IO ByteString
requestSock :: Socket
mySockAddr :: SockAddr
peerSockAddr :: SockAddr
..} =
IO Config -> (Config -> IO ()) -> (Config -> IO ()) -> IO ()
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
E.bracket
(Settings
-> Manager
-> (ByteString -> IO ())
-> IO ByteString
-> SockAddr
-> SockAddr
-> IO Config
allocConfigForServer Settings
settings0 Manager
mgr ByteString -> IO ()
send IO ByteString
recv SockAddr
mySockAddr SockAddr
peerSockAddr)
Config -> IO ()
freeConfigForServer
(\Config
conf -> ServerConfig -> Config -> (ServerIO Stream -> IO (IO ())) -> IO ()
H2I.runIO ServerConfig
sconf Config
conf ServerIO Stream -> IO (IO ())
action)
where
sconf :: ServerConfig
sconf =
ServerConfig
defaultServerConfig
{ connectionWindowSize = settingsConnectionWindowSize
, settings =
(settings defaultServerConfig)
{ initialWindowSize = settingsStreamWindowSize
, maxConcurrentStreams = Just settingsConcurrentStreams
, pingRateLimit = settingsPingRateLimit
, emptyFrameRateLimit = settingsEmptyFrameRateLimit
, settingsRateLimit = settingsSettingsRateLimit
, rstRateLimit = settingsRstRateLimit
}
}
runIOH2C
:: Settings -> Socket -> (ServerIO Stream -> IO (IO ())) -> IO ()
runIOH2C :: Settings -> Socket -> (ServerIO Stream -> IO (IO ())) -> IO ()
runIOH2C settings0 :: Settings
settings0@Settings{Int
SessionManager
HostName -> IO ()
settingsTimeout :: Settings -> Int
settingsSendBufferSize :: Settings -> Int
settingsSlowlorisSize :: Settings -> Int
settingsReadBufferSize :: Settings -> Int
settingsReadBufferLowerLimit :: Settings -> Int
settingsKeyLogger :: Settings -> HostName -> IO ()
settingsNumberOfWorkers :: Settings -> Int
settingsConcurrentStreams :: Settings -> Int
settingsConnectionWindowSize :: Settings -> Int
settingsStreamWindowSize :: Settings -> Int
settingsSessionManager :: Settings -> SessionManager
settingsEarlyDataSize :: Settings -> Int
settingsPingRateLimit :: Settings -> Int
settingsEmptyFrameRateLimit :: Settings -> Int
settingsSettingsRateLimit :: Settings -> Int
settingsRstRateLimit :: Settings -> Int
settingsTimeout :: Int
settingsSendBufferSize :: Int
settingsSlowlorisSize :: Int
settingsReadBufferSize :: Int
settingsReadBufferLowerLimit :: Int
settingsKeyLogger :: HostName -> IO ()
settingsNumberOfWorkers :: Int
settingsConcurrentStreams :: Int
settingsStreamWindowSize :: Int
settingsConnectionWindowSize :: Int
settingsSessionManager :: SessionManager
settingsEarlyDataSize :: Int
settingsPingRateLimit :: Int
settingsEmptyFrameRateLimit :: Int
settingsSettingsRateLimit :: Int
settingsRstRateLimit :: Int
..} Socket
s ServerIO Stream -> IO (IO ())
action =
Int -> Socket -> TimeoutServer () -> IO ()
forall a. Int -> Socket -> TimeoutServer a -> IO a
runTCPServerWithSocket
Int
settingsTimeout
Socket
s
(TimeoutServer () -> IO ()) -> TimeoutServer () -> IO ()
forall a b. (a -> b) -> a -> b
$ \Manager
mgr Handle
th Socket
sock -> do
IOBackend
iobackend0 <- Settings -> Socket -> IO IOBackend
tcpIOBackend Settings
settings0 Socket
sock
let iobackend :: IOBackend
iobackend = Handle -> Settings -> IOBackend -> IOBackend
timeoutIOBackend Handle
th Settings
settings0 IOBackend
iobackend0
Settings
-> (ServerIO Stream -> IO (IO ())) -> Manager -> IOBackend -> IO ()
runIO' Settings
settings0 ServerIO Stream -> IO (IO ())
action Manager
mgr IOBackend
iobackend
getServerParams
:: Settings
-> Credentials
-> ByteString
-> ServerParams
getServerParams :: Settings -> Credentials -> ByteString -> ServerParams
getServerParams Settings{Int
SessionManager
HostName -> IO ()
settingsTimeout :: Settings -> Int
settingsSendBufferSize :: Settings -> Int
settingsSlowlorisSize :: Settings -> Int
settingsReadBufferSize :: Settings -> Int
settingsReadBufferLowerLimit :: Settings -> Int
settingsKeyLogger :: Settings -> HostName -> IO ()
settingsNumberOfWorkers :: Settings -> Int
settingsConcurrentStreams :: Settings -> Int
settingsConnectionWindowSize :: Settings -> Int
settingsStreamWindowSize :: Settings -> Int
settingsSessionManager :: Settings -> SessionManager
settingsEarlyDataSize :: Settings -> Int
settingsPingRateLimit :: Settings -> Int
settingsEmptyFrameRateLimit :: Settings -> Int
settingsSettingsRateLimit :: Settings -> Int
settingsRstRateLimit :: Settings -> Int
settingsTimeout :: Int
settingsSendBufferSize :: Int
settingsSlowlorisSize :: Int
settingsReadBufferSize :: Int
settingsReadBufferLowerLimit :: Int
settingsKeyLogger :: HostName -> IO ()
settingsNumberOfWorkers :: Int
settingsConcurrentStreams :: Int
settingsStreamWindowSize :: Int
settingsConnectionWindowSize :: Int
settingsSessionManager :: SessionManager
settingsEarlyDataSize :: Int
settingsPingRateLimit :: Int
settingsEmptyFrameRateLimit :: Int
settingsSettingsRateLimit :: Int
settingsRstRateLimit :: Int
..} Credentials
creds ByteString
alpn =
ServerParams
defaultParamsServer
{ serverSupported = supported
, serverShared = shared
, serverHooks = hooks
, serverDebug = debug
, serverEarlyDataSize = settingsEarlyDataSize
}
where
shared :: Shared
shared =
Shared
defaultShared
{ sharedCredentials = creds
, sharedSessionManager = settingsSessionManager
}
supported :: Supported
supported = Supported
strongSupported
hooks :: ServerHooks
hooks =
ServerHooks
defaultServerHooks
{ onALPNClientSuggest = Just $ selectALPN alpn
}
debug :: DebugParams
debug =
DebugParams
defaultDebugParams
{ debugKeyLogger = settingsKeyLogger
}
selectALPN :: ByteString -> [ByteString] -> IO ByteString
selectALPN :: ByteString -> [ByteString] -> IO ByteString
selectALPN ByteString
key [ByteString]
xs
| ByteString
key ByteString -> [ByteString] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [ByteString]
xs = ByteString -> IO ByteString
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
key
| Bool
otherwise = ByteString -> IO ByteString
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
""