module Hreq.Client.Internal.Config
(
HttpConfig (..)
, StatusRange (..)
, createDefConfig
) where
import Control.Concurrent.STM.TVar (TVar)
import Control.Retry (RetryPolicy, retryPolicyDefault)
import qualified Network.HTTP.Client as C
import qualified Network.HTTP.Client.TLS as TLS
import Hreq.Core.API (StatusCode)
import Hreq.Core.Client
data StatusRange = StatusRange
{ statusUpper :: StatusCode
, statusLower :: StatusCode
}
data HttpConfig = HttpConfig
{ httpBaseUrl :: BaseUrl
, httpStatuses :: StatusRange
, httpCookieJar :: Maybe (TVar C.CookieJar)
, httpRetryPolicy :: RetryPolicy
, httpManager :: C.Manager
}
createDefConfig :: BaseUrl -> IO HttpConfig
createDefConfig baseUrl@(BaseUrl scheme _ _ _) =
HttpConfig baseUrl (StatusRange 200 300) Nothing retryPolicyDefault <$> manager
where
manager :: IO C.Manager
manager = case scheme of
Http -> C.newManager C.defaultManagerSettings
Https -> C.newManager TLS.tlsManagerSettings