Extended config data types with time bound option

Implemented connection time bound option for both V04 and V10
configurations, default value is set to 5000ms.
This commit is contained in:
Артур Файзрахманов 2015-04-30 08:59:22 +05:00
parent 107ddf9e5e
commit f74a95a852
3 changed files with 29 additions and 18 deletions

View File

@ -72,14 +72,15 @@ instance FromJSON Redirect where
parseJSON _ = fail "Wanted an object"
data KeterConfig = KeterConfig
{ kconfigDir :: F.FilePath
, kconfigPortMan :: PortSettings
, kconfigHost :: HostPreference
, kconfigPort :: Port
, kconfigSsl :: Maybe TLSConfig
, kconfigSetuid :: Maybe Text
, kconfigReverseProxy :: Set ReverseProxyConfig
, kconfigIpFromHeader :: Bool
{ kconfigDir :: F.FilePath
, kconfigPortMan :: PortSettings
, kconfigHost :: HostPreference
, kconfigPort :: Port
, kconfigSsl :: Maybe TLSConfig
, kconfigSetuid :: Maybe Text
, kconfigReverseProxy :: Set ReverseProxyConfig
, kconfigIpFromHeader :: Bool
, kconfigConnectionTimeBound :: Int
}
instance Default KeterConfig where
@ -92,6 +93,7 @@ instance Default KeterConfig where
, kconfigSetuid = Nothing
, kconfigReverseProxy = Set.empty
, kconfigIpFromHeader = False
, kconfigConnectionTimeBound = 5000
}
instance ParseYamlFile KeterConfig where
@ -104,6 +106,7 @@ instance ParseYamlFile KeterConfig where
<*> o .:? "setuid"
<*> o .:? "reverse-proxy" .!= Set.empty
<*> o .:? "ip-from-header" .!= False
<*> o .:? "connection-time-bound" .!= 5000
data TLSConfig = TLSConfig !Warp.Settings !WarpTLS.TLSSettings

View File

@ -87,23 +87,24 @@ instance ParseYamlFile ListeningPort where
_ -> fail "Must provide both certificate and key files"
data KeterConfig = KeterConfig
{ kconfigDir :: F.FilePath
, kconfigPortPool :: V04.PortSettings
, kconfigListeners :: !(NonEmptyVector ListeningPort)
, kconfigSetuid :: Maybe Text
, kconfigBuiltinStanzas :: !(V.Vector (Stanza ()))
, kconfigIpFromHeader :: Bool
, kconfigExternalHttpPort :: !Int
{ kconfigDir :: F.FilePath
, kconfigPortPool :: V04.PortSettings
, kconfigListeners :: !(NonEmptyVector ListeningPort)
, kconfigSetuid :: Maybe Text
, kconfigBuiltinStanzas :: !(V.Vector (Stanza ()))
, kconfigIpFromHeader :: Bool
, kconfigExternalHttpPort :: !Int
-- ^ External HTTP port when generating APPROOTs.
, kconfigExternalHttpsPort :: !Int
, kconfigExternalHttpsPort :: !Int
-- ^ External HTTPS port when generating APPROOTs.
, kconfigEnvironment :: !(Map Text Text)
, kconfigEnvironment :: !(Map Text Text)
-- ^ Environment variables to be passed to all apps.
, kconfigConnectionTimeBound :: !Int
}
instance ToCurrent KeterConfig where
type Previous KeterConfig = V04.KeterConfig
toCurrent (V04.KeterConfig dir portman host port ssl setuid rproxy ipFromHeader) = KeterConfig
toCurrent (V04.KeterConfig dir portman host port ssl setuid rproxy ipFromHeader connectionTimeBound) = KeterConfig
{ kconfigDir = dir
, kconfigPortPool = portman
, kconfigListeners = NonEmptyVector (LPInsecure host port) (getSSL ssl)
@ -113,6 +114,7 @@ instance ToCurrent KeterConfig where
, kconfigExternalHttpPort = 80
, kconfigExternalHttpsPort = 443
, kconfigEnvironment = Map.empty
, kconfigConnectionTimeBound = connectionTimeBound
}
where
getSSL Nothing = V.empty
@ -134,6 +136,7 @@ instance Default KeterConfig where
, kconfigExternalHttpPort = 80
, kconfigExternalHttpsPort = 443
, kconfigEnvironment = Map.empty
, kconfigConnectionTimeBound = 5000
}
instance ParseYamlFile KeterConfig where
@ -153,6 +156,7 @@ instance ParseYamlFile KeterConfig where
<*> o .:? "external-http-port" .!= 80
<*> o .:? "external-https-port" .!= 443
<*> o .:? "env" .!= Map.empty
<*> o .:? "connection-time-bound" .!= 5000
-- | Whether we should force redirect to HTTPS routes.
type RequiresSecure = Bool

View File

@ -32,3 +32,7 @@ listeners:
# Set additional environment variables for all apps
# env:
# key: value
# Connection time bound in milliseconds, set to 0 to have no time bound,
# i.e. keep connections alive indefinitely. Default value is 5000.
# connection-time-bound: 5000