@@ -122,6 +122,7 @@ module Network.HTTP.Req
122 -- $embedding-requests
122 -- $embedding-requests
123 , MonadHttp (..)
123 , MonadHttp (..)
124 , HttpConfig (..)
124 , HttpConfig (..)
127 -- * Request
128 -- * Request
@@ -224,7 +225,6 @@ import Control.Retry
224import Data.Aeson (ToJSON (..), FromJSON (..))
225import Data.Aeson (ToJSON (..), FromJSON (..))
225import Data.ByteString (ByteString)
226import Data.ByteString (ByteString)
226import Data.Data (Data)
227import Data.Data (Data)
227−import Data.Default.Class
228import Data.Function (on)
228import Data.Function (on)
229import Data.IORef
229import Data.IORef
230import Data.List (nubBy)
230import Data.List (nubBy)
@@ -318,7 +318,6 @@ import GHC.Exts (Constraint)
318-- > import Control.Monad
318-- > import Control.Monad
319-- > import Control.Monad.IO.Class
319-- > import Control.Monad.IO.Class
320-- > import Data.Aeson
320-- > import Data.Aeson
321−-- > import Data.Default.Class
322-- > import Data.Maybe (fromJust)
321-- > import Data.Maybe (fromJust)
323-- > import Data.Monoid ((<>))
322-- > import Data.Monoid ((<>))
324-- > import Data.Text (Text)
323-- > import Data.Text (Text)
@@ -331,7 +330,7 @@ import GHC.Exts (Constraint)
331-- Make a GET request, grab 5 random bytes:
330-- Make a GET request, grab 5 random bytes:
333-- > main :: IO ()
332-- > main :: IO ()
334−-- > main = runReq def $ do
333+-- > main = runReq defaultHttpConfig $ do
335-- > let n :: Int
334-- > let n :: Int
336-- > n = 5
335-- > n = 5
337-- > bs <- req GET (https "httpbin.org" /: "bytes" /~ n) NoReqBody bsResponse mempty
336-- > bs <- req GET (https "httpbin.org" /: "bytes" /~ n) NoReqBody bsResponse mempty
@@ -341,7 +340,7 @@ import GHC.Exts (Constraint)
341-- seed of the generator:
340-- seed of the generator:
343-- > main :: IO ()
342-- > main :: IO ()
344−-- > main = runReq def $ do
343+-- > main = runReq defaultHttpConfig $ do
345-- > let n, seed :: Int
344-- > let n, seed :: Int
346-- > n = 5
345-- > n = 5
347-- > seed = 100
346-- > seed = 100
@@ -360,7 +359,7 @@ import GHC.Exts (Constraint)
360-- > instance FromJSON MyData
359-- > instance FromJSON MyData
362-- > main :: IO ()
361-- > main :: IO ()
363−-- > main = runReq def $ do
362+-- > main = runReq defaultHttpConfig $ do
364-- > let myData = MyData
363-- > let myData = MyData
365-- > { size = 6
364-- > { size = 6
366-- > , color = "Green" }
365-- > , color = "Green" }
@@ -370,7 +369,7 @@ import GHC.Exts (Constraint)
370-- Sending URL-encoded body:
369-- Sending URL-encoded body:
372-- > main :: IO ()
371-- > main :: IO ()
373−-- > main = runReq def $ do
372+-- > main = runReq defaultHttpConfig $ do
374-- > let params =
373-- > let params =
375-- > "foo" =: ("bar" :: Text) <>
374-- > "foo" =: ("bar" :: Text) <>
376-- > queryFlag "baz"
375-- > queryFlag "baz"
@@ -380,7 +379,7 @@ import GHC.Exts (Constraint)
380-- Using various optional parameters and URL that is not known in advance:
379-- Using various optional parameters and URL that is not known in advance:
382-- > main :: IO ()
381-- > main :: IO ()
383−-- > main = runReq def $ do
382+-- > main = runReq defaultHttpConfig $ do
384-- > -- This is an example of what to do when URL is given dynamically. Of
383-- > -- This is an example of what to do when URL is given dynamically. Of
385-- > -- course in a real application you may not want to use 'fromJust'.
384-- > -- course in a real application you may not want to use 'fromJust'.
386-- > let (url, options) = fromJust (parseUrlHttps "https://httpbin.org/get?foo=bar")
385-- > let (url, options) = fromJust (parseUrlHttps "https://httpbin.org/get?foo=bar")
@@ -511,7 +510,10 @@ withReqManager m = liftIO (readIORef globalManager) >>= m
511globalManager :: IORef L.Manager
510globalManager :: IORef L.Manager
512globalManager = unsafePerformIO $ do
511globalManager = unsafePerformIO $ do
513 context <- NC.initConnectionContext
512 context <- NC.initConnectionContext
514− let settings = L.mkManagerSettingsContext (Just context) def Nothing
513+ let settings = L.mkManagerSettingsContext
515+ (NC.TLSSettingsSimple False False False)
515 manager <- L.newManager settings
517 manager <- L.newManager settings
516 newIORef manager
518 newIORef manager
517{-# NOINLINE globalManager #-}
519{-# NOINLINE globalManager #-}
@@ -552,7 +554,7 @@ class MonadIO m => MonadHttp m where
552 -- approach to configuration is desirable.
554 -- approach to configuration is desirable.
554 getHttpConfig :: m HttpConfig
556 getHttpConfig :: m HttpConfig
555− getHttpConfig = return def
557+ getHttpConfig = return defaultHttpConfig
557-- | 'HttpConfig' contains general and default settings to be used when
559-- | 'HttpConfig' contains general and default settings to be used when
558-- making HTTP requests.
560-- making HTTP requests.
@@ -615,28 +617,32 @@ data HttpConfig = HttpConfig
615 -- @since 0.3.0
617 -- @since 0.3.0
616 } deriving Typeable
618 } deriving Typeable
618−instance Default HttpConfig where
620+-- | Default value of 'HttpConfig'.
624+defaultHttpConfig :: HttpConfig
619− def = HttpConfig
625+defaultHttpConfig = HttpConfig
620− { httpConfigProxy = Nothing
626+ { httpConfigProxy = Nothing
621− , httpConfigRedirectCount = 10
627+ , httpConfigRedirectCount = 10
622− , httpConfigAltManager = Nothing
628+ , httpConfigAltManager = Nothing
623− , httpConfigCheckResponse = \_ response preview ->
629+ , httpConfigCheckResponse = \_ response preview ->
624− let scode = statusCode response
630+ let scode = statusCode response
625− in if 200 <= scode && scode < 300
631+ in if 200 <= scode && scode < 300
626− then Nothing
632+ then Nothing
627− else Just (L.StatusCodeException (void response) preview)
633+ else Just (L.StatusCodeException (void response) preview)
628− , httpConfigRetryPolicy = def
634+ , httpConfigRetryPolicy = retryPolicyDefault
629− , httpConfigRetryJudge = \_ response ->
635+ , httpConfigRetryJudge = \_ response ->
630− statusCode response `elem`
636+ statusCode response `elem`
631− [ 408 -- Request timeout
637+ [ 408 -- Request timeout
632− , 504 -- Gateway timeout
638+ , 504 -- Gateway timeout
633− , 524 -- A timeout occurred
639+ , 524 -- A timeout occurred
634− , 598 -- (Informal convention) Network read timeout error
640+ , 598 -- (Informal convention) Network read timeout error
635− , 599 -- (Informal convention) Network connect timeout error
641+ , 599 -- (Informal convention) Network connect timeout error
639− statusCode = Y.statusCode . L.responseStatus
645+ statusCode = Y.statusCode . L.responseStatus
641instance RequestComponent HttpConfig where
647instance RequestComponent HttpConfig where
642 getRequestMod HttpConfig {..} = Endo $ \x ->
648 getRequestMod HttpConfig {..} = Endo $ \x ->