on master help sign in
Get rid of ‘data-default-class’
94c1352ocramz
CHANGELOG.md+5
@@ -1,3 +1,8 @@
1+## Req 2.0.0
2+
3+* Got rid of `data-default-class` dependency, now we export
4+ `defaultHttpConfig` instead.
5+
1## Req 1.2.1
6## Req 1.2.1
2
7
3* Fixed a typo in the type signature of `parseUrl`.
8* Fixed a typo in the type signature of `parseUrl`.
Network/HTTP/Req.hs+37−31
@@ -122,6 +122,7 @@ module Network.HTTP.Req
122 -- $embedding-requests
122 -- $embedding-requests
123 , MonadHttp (..)
123 , MonadHttp (..)
124 , HttpConfig (..)
124 , HttpConfig (..)
125+ , defaultHttpConfig
125 , Req
126 , Req
126 , runReq
127 , runReq
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:
332--
331--
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:
342--
341--
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
361-- >
360-- >
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:
371--
370--
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:
381--
380--
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
514+ (Just context)
515+ (NC.TLSSettingsSimple False False False)
516+ Nothing
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.
553
555
554 getHttpConfig :: m HttpConfig
556 getHttpConfig :: m HttpConfig
555− getHttpConfig = return def
557+ getHttpConfig = return defaultHttpConfig
556
558
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
617
619
618−instance Default HttpConfig where
620+-- | Default value of 'HttpConfig'.
621+--
622+-- @since 2.0.0
623+
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
636− ]
642+ ]
637− }
643+ }
638− where
644+ where
639− statusCode = Y.statusCode . L.responseStatus
645+ statusCode = Y.statusCode . L.responseStatus
640
646
641instance RequestComponent HttpConfig where
647instance RequestComponent HttpConfig where
642 getRequestMod HttpConfig {..} = Endo $ \x ->
648 getRequestMod HttpConfig {..} = Endo $ \x ->
README.md+1−2
@@ -20,13 +20,12 @@ module Main (main) where
20
20
21import Control.Monad.IO.Class
21import Control.Monad.IO.Class
22import Data.Aeson
22import Data.Aeson
23−import Data.Default.Class
24import Network.HTTP.Req
23import Network.HTTP.Req
25
24
26main :: IO ()
25main :: IO ()
27-- You can either make your monad an instance of 'MonadHttp', or use
26-- You can either make your monad an instance of 'MonadHttp', or use
28-- 'runReq' in any IO-enabled monad without defining new instances.
27-- 'runReq' in any IO-enabled monad without defining new instances.
29−main = runReq def $ do
28+main = runReq defaultHttpConfig $ do
30 let payload = object
29 let payload = object
31 [ "foo" .= (10 :: Int)
30 [ "foo" .= (10 :: Int)
32 , "bar" .= (20 :: Int) ]
31 , "bar" .= (20 :: Int) ]
httpbin-tests/Network/HTTP/ReqSpec.hs+3−4
@@ -13,7 +13,6 @@ import Control.Exception
13import Control.Monad.Reader
13import Control.Monad.Reader
14import Control.Monad.Trans.Control
14import Control.Monad.Trans.Control
15import Data.Aeson (Value (..), ToJSON (..), object, (.=))
15import Data.Aeson (Value (..), ToJSON (..), object, (.=))
16−import Data.Default.Class
17import Data.Monoid ((<>))
16import Data.Monoid ((<>))
18import Data.Proxy
17import Data.Proxy
19import Data.Text (Text)
18import Data.Text (Text)
@@ -41,7 +40,7 @@ spec = do
41
40
42 describe "exception throwing on non-2xx status codes (Req monad)" $
41 describe "exception throwing on non-2xx status codes (Req monad)" $
43 it "throws indeed for non-2xx" $
42 it "throws indeed for non-2xx" $
44− asIO . runReq def $
43+ asIO . runReq defaultHttpConfig $
45 liftBaseWith $ \run ->
44 liftBaseWith $ \run ->
46 run (req GET (httpbin /: "foo") NoReqBody ignoreResponse mempty)
45 run (req GET (httpbin /: "foo") NoReqBody ignoreResponse mempty)
47 `shouldThrow` selector404
46 `shouldThrow` selector404
@@ -322,14 +321,14 @@ instance MonadHttp IO where
322-- response status codes.
321-- response status codes.
323
322
324prepareForShit :: Req a -> IO a
323prepareForShit :: Req a -> IO a
325−prepareForShit = runReq def { httpConfigCheckResponse = noNoise }
324+prepareForShit = runReq defaultHttpConfig { httpConfigCheckResponse = noNoise }
326 where
325 where
327 noNoise _ _ _ = Nothing
326 noNoise _ _ _ = Nothing
328
327
329-- | Run request with such settings that it throws on any response.
328-- | Run request with such settings that it throws on any response.
330
329
331blindlyThrowing :: Req a -> IO a
330blindlyThrowing :: Req a -> IO a
332−blindlyThrowing = runReq def { httpConfigCheckResponse = doit }
331+blindlyThrowing = runReq defaultHttpConfig { httpConfigCheckResponse = doit }
333 where
332 where
334 doit _ _ = error "Oops!"
333 doit _ _ = error "Oops!"
335
334
pure-tests/Network/HTTP/ReqSpec.hs+3−3
@@ -14,9 +14,9 @@ module Network.HTTP.ReqSpec
14where
14where
15
15
16import Control.Exception (throwIO)
16import Control.Exception (throwIO)
17+import Control.Retry
17import Data.Aeson (ToJSON (..))
18import Data.Aeson (ToJSON (..))
18import Data.ByteString (ByteString)
19import Data.ByteString (ByteString)
19−import Data.Default.Class
20import Data.Maybe (isNothing, fromJust)
20import Data.Maybe (isNothing, fromJust)
21import Data.Monoid ((<>))
21import Data.Monoid ((<>))
22import Data.Proxy
22import Data.Proxy
@@ -266,7 +266,7 @@ spec = do
266 (oAuth2Bearer token0 <> oAuth2Bearer token1)
266 (oAuth2Bearer token0 <> oAuth2Bearer token1)
267 lookup "Authorization" (L.requestHeaders request) `shouldBe`
267 lookup "Authorization" (L.requestHeaders request) `shouldBe`
268 pure ("Bearer " <> token0)
268 pure ("Bearer " <> token0)
269− describe "ProxyAuthorization" $ do
269+ describe "ProxyAuthorization" $
270 it "sets Authorization header to correct value" $
270 it "sets Authorization header to correct value" $
271 property $ \username password -> do
271 property $ \username password -> do
272 request <- req_ GET url NoReqBody (basicProxyAuth username password)
272 request <- req_ GET url NoReqBody (basicProxyAuth username password)
@@ -326,7 +326,7 @@ instance Arbitrary HttpConfig where
326 httpConfigRedirectCount <- arbitrary
326 httpConfigRedirectCount <- arbitrary
327 let httpConfigAltManager = Nothing
327 let httpConfigAltManager = Nothing
328 httpConfigCheckResponse _ _ _ = Nothing
328 httpConfigCheckResponse _ _ _ = Nothing
329− httpConfigRetryPolicy = def
329+ httpConfigRetryPolicy = retryPolicyDefault
330 httpConfigRetryJudge _ _ = False
330 httpConfigRetryJudge _ _ = False
331 return HttpConfig {..}
331 return HttpConfig {..}
332
332
req.cabal+3−5
@@ -1,5 +1,5 @@
1name: req
1name: req
2−version: 1.2.1
2+version: 2.0.0
3cabal-version: 1.18
3cabal-version: 1.18
4tested-with: GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.4, GHC==8.6.3
4tested-with: GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.4, GHC==8.6.3
5license: BSD3
5license: BSD3
@@ -34,14 +34,13 @@ library
34 , bytestring >= 0.10.8 && < 0.11
34 , bytestring >= 0.10.8 && < 0.11
35 , case-insensitive >= 0.2 && < 1.3
35 , case-insensitive >= 0.2 && < 1.3
36 , connection >= 0.2.2 && < 0.3
36 , connection >= 0.2.2 && < 0.3
37− , data-default-class
38 , http-api-data >= 0.2 && < 0.5
37 , http-api-data >= 0.2 && < 0.5
39 , http-client >= 0.5 && < 0.7
38 , http-client >= 0.5 && < 0.7
40 , http-client-tls >= 0.3.2 && < 0.4
39 , http-client-tls >= 0.3.2 && < 0.4
41 , http-types >= 0.8 && < 10.0
40 , http-types >= 0.8 && < 10.0
42 , monad-control >= 1.0 && < 1.1
41 , monad-control >= 1.0 && < 1.1
43 , mtl >= 2.0 && < 3.0
42 , mtl >= 2.0 && < 3.0
44− , retry >= 0.7 && < 0.8
43+ , retry >= 0.8 && < 0.9
45 , text >= 0.2 && < 1.3
44 , text >= 0.2 && < 1.3
46 , time >= 1.2 && < 1.9
45 , time >= 1.2 && < 1.9
47 , transformers >= 0.4 && < 0.6
46 , transformers >= 0.4 && < 0.6
@@ -72,13 +71,13 @@ test-suite pure-tests
72 , blaze-builder >= 0.3 && < 0.5
71 , blaze-builder >= 0.3 && < 0.5
73 , bytestring >= 0.10.8 && < 0.11
72 , bytestring >= 0.10.8 && < 0.11
74 , case-insensitive >= 0.2 && < 1.3
73 , case-insensitive >= 0.2 && < 1.3
75− , data-default-class
76 , hspec >= 2.0 && < 3.0
74 , hspec >= 2.0 && < 3.0
77 , hspec-core >= 2.0 && < 3.0
75 , hspec-core >= 2.0 && < 3.0
78 , http-client >= 0.5 && < 0.7
76 , http-client >= 0.5 && < 0.7
79 , http-types >= 0.8 && < 10.0
77 , http-types >= 0.8 && < 10.0
80 , mtl >= 2.0 && < 3.0
78 , mtl >= 2.0 && < 3.0
81 , req
79 , req
80+ , retry >= 0.8 && < 0.9
82 , text >= 0.2 && < 1.3
81 , text >= 0.2 && < 1.3
83 , time >= 1.2 && < 1.9
82 , time >= 1.2 && < 1.9
84 build-tools: hspec-discover >= 2.0 && < 3.0
83 build-tools: hspec-discover >= 2.0 && < 3.0
@@ -97,7 +96,6 @@ test-suite httpbin-tests
97 , aeson >= 0.9 && < 1.5
96 , aeson >= 0.9 && < 1.5
98 , base >= 4.8 && < 5.0
97 , base >= 4.8 && < 5.0
99 , bytestring >= 0.10.8 && < 0.11
98 , bytestring >= 0.10.8 && < 0.11
100− , data-default-class
101 , hspec >= 2.0 && < 3.0
99 , hspec >= 2.0 && < 3.0
102 , http-client >= 0.5 && < 0.7
100 , http-client >= 0.5 && < 0.7
103 , http-types >= 0.8 && < 10.0
101 , http-types >= 0.8 && < 10.0