aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2017-09-21 18:09:23 +0300
committerIgor Pashev <pashev.igor@gmail.com>2017-09-21 18:09:23 +0300
commit9cdee8017606580a3c4e8ca7de854cf90e41d9cf (patch)
treef903d0d69ab4df18ac8187d9b39e1efbb2921db1
parent392d665b9beeb767a2adbd75b9147c41a4d2a033 (diff)
downloadsproxy2-9cdee8017606580a3c4e8ca7de854cf90e41d9cf.tar.gz
Allow configure backend response timeout
-rw-r--r--sproxy.example.yml2
-rw-r--r--src/Sproxy/Config.hs4
-rw-r--r--src/Sproxy/Server.hs3
3 files changed, 7 insertions, 2 deletions
diff --git a/sproxy.example.yml b/sproxy.example.yml
index c67afba..f87d97b 100644
--- a/sproxy.example.yml
+++ b/sproxy.example.yml
@@ -164,6 +164,8 @@ ssl_key: /path/key.pem
# cookie_name - sproxy cookie name. Optional. Default is "sproxy".
# cookie_domain - sproxy cookie domain. Optional. Default is the request host name as per RFC2109.
# cookie_max_age - sproxy cookie shelflife in seconds. Optional. Default is 604800 (7 days).
+#
+# timeout - response timeout in seconds. Optional. Default is 30.
# conn_count - number of connections to keep alive. Optional. Default is 32.
# This is specific to Haskell HTTP Client library, and is per host name,
# not per backend. HTTP Client's default is 10.
diff --git a/src/Sproxy/Config.hs b/src/Sproxy/Config.hs
index f1d8004..cb32a06 100644
--- a/src/Sproxy/Config.hs
+++ b/src/Sproxy/Config.hs
@@ -65,6 +65,7 @@ data BackendConf = BackendConf
, beCookieDomain :: Maybe String
, beCookieMaxAge :: Int64
, beConnCount :: Int
+ , beTimeout :: Int
} deriving (Show)
instance FromJSON BackendConf where
@@ -75,7 +76,8 @@ instance FromJSON BackendConf where
m .:? "cookie_name" .!= "sproxy" <*>
m .:? "cookie_domain" <*>
m .:? "cookie_max_age" .!= (7 * 24 * 60 * 60) <*>
- m .:? "conn_count" .!= 32
+ m .:? "conn_count" .!= 32 <*>
+ m .:? "timeout" .!= 30
parseJSON _ = empty
data OAuth2Conf = OAuth2Conf
diff --git a/src/Sproxy/Server.hs b/src/Sproxy/Server.hs
index 75a50a4..2477364 100644
--- a/src/Sproxy/Server.hs
+++ b/src/Sproxy/Server.hs
@@ -13,7 +13,7 @@ import Data.Word (Word16)
import Data.Yaml.Include (decodeFileEither)
import Network.HTTP.Client
(Manager, ManagerSettings(..), defaultManagerSettings, newManager,
- socketConnection)
+ responseTimeoutMicro, socketConnection)
import Network.HTTP.Client.Internal (Connection)
import Network.Socket
(Family(AF_INET, AF_UNIX), SockAddr(SockAddrInet, SockAddrUnix),
@@ -152,6 +152,7 @@ newBackendManager be = do
defaultManagerSettings
{ managerRawConnection = return $ \_ _ _ -> openConn
, managerConnCount = beConnCount be
+ , managerResponseTimeout = responseTimeoutMicro (1000000 * beTimeout be)
}
newServer :: ConfigFile -> IO (Settings -> Socket -> Application -> IO ())