on master help sign in
Get rid of ‘data-default-class’
commit94c1352f8f72729037426f18cbecc73eb4181dd8 authorocramz <zocca.marco@gmail.com> dateMon 7 Jan 2019, 18:57 (8 years ago) parentb04dfba
6 files changed+52−45
CHANGELOG.md+5 Network/HTTP/Req.hs+37−31 README.md+1−2 httpbin-tests/Network/HTTP/ReqSpec.hs+3−4 pure-tests/Network/HTTP/ReqSpec.hs+3−3 req.cabal+3−5
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+
16## Req 1.2.1
27
38* Fixed a typo in the type signature of `parseUrl`.
Network/HTTP/Req.hs+37−31
@@ -122,6 +122,7 @@ module Network.HTTP.Req
122122 -- $embedding-requests
123123 , MonadHttp (..)
124124 , HttpConfig (..)
125+ , defaultHttpConfig
125126 , Req
126127 , runReq
127128 -- * Request
@@ -224,7 +225,6 @@ import Control.Retry
224225import Data.Aeson (ToJSON (..), FromJSON (..))
225226import Data.ByteString (ByteString)
226227import Data.Data (Data)
227−import Data.Default.Class
228228import Data.Function (on)
229229import Data.IORef
230230import Data.List (nubBy)
@@ -318,7 +318,6 @@ import GHC.Exts (Constraint)
318318-- > import Control.Monad
319319-- > import Control.Monad.IO.Class
320320-- > import Data.Aeson
321−-- > import Data.Default.Class
322321-- > import Data.Maybe (fromJust)
323322-- > import Data.Monoid ((<>))
324323-- > import Data.Text (Text)
@@ -331,7 +330,7 @@ import GHC.Exts (Constraint)
331330-- Make a GET request, grab 5 random bytes:
332331--
333332-- > main :: IO ()
334−-- > main = runReq def $ do
333+-- > main = runReq defaultHttpConfig $ do
335334-- > let n :: Int
336335-- > n = 5
337336-- > bs <- req GET (https "httpbin.org" /: "bytes" /~ n) NoReqBody bsResponse mempty
@@ -341,7 +340,7 @@ import GHC.Exts (Constraint)
341340-- seed of the generator:
342341--
343342-- > main :: IO ()
344−-- > main = runReq def $ do
343+-- > main = runReq defaultHttpConfig $ do
345344-- > let n, seed :: Int
346345-- > n = 5
347346-- > seed = 100
@@ -360,7 +359,7 @@ import GHC.Exts (Constraint)
360359-- > instance FromJSON MyData
361360-- >
362361-- > main :: IO ()
363−-- > main = runReq def $ do
362+-- > main = runReq defaultHttpConfig $ do
364363-- > let myData = MyData
365364-- > { size = 6
366365-- > , color = "Green" }
@@ -370,7 +369,7 @@ import GHC.Exts (Constraint)
370369-- Sending URL-encoded body:
371370--
372371-- > main :: IO ()
373−-- > main = runReq def $ do
372+-- > main = runReq defaultHttpConfig $ do
374373-- > let params =
375374-- > "foo" =: ("bar" :: Text) <>
376375-- > queryFlag "baz"
@@ -380,7 +379,7 @@ import GHC.Exts (Constraint)
380379-- Using various optional parameters and URL that is not known in advance:
381380--
382381-- > main :: IO ()
383−-- > main = runReq def $ do
382+-- > main = runReq defaultHttpConfig $ do
384383-- > -- This is an example of what to do when URL is given dynamically. Of
385384-- > -- course in a real application you may not want to use 'fromJust'.
386385-- > let (url, options) = fromJust (parseUrlHttps "https://httpbin.org/get?foo=bar")
@@ -511,7 +510,10 @@ withReqManager m = liftIO (readIORef globalManager) >>= m
511510globalManager :: IORef L.Manager
512511globalManager = unsafePerformIO $ do
513512 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
515517 manager <- L.newManager settings
516518 newIORef manager
517519{-# NOINLINE globalManager #-}
@@ -552,7 +554,7 @@ class MonadIO m => MonadHttp m where
552554 -- approach to configuration is desirable.
553555
554556 getHttpConfig :: m HttpConfig
555− getHttpConfig = return def
557+ getHttpConfig = return defaultHttpConfig
556558
557559-- | 'HttpConfig' contains general and default settings to be used when
558560-- making HTTP requests.
@@ -615,28 +617,32 @@ data HttpConfig = HttpConfig
615617 -- @since 0.3.0
616618 } deriving Typeable
617619
618−instance Default HttpConfig where
619− def = HttpConfig
620− { httpConfigProxy = Nothing
621− , httpConfigRedirectCount = 10
622− , httpConfigAltManager = Nothing
623− , httpConfigCheckResponse = \_ response preview ->
624− let scode = statusCode response
625− in if 200 <= scode && scode < 300
626− then Nothing
627− else Just (L.StatusCodeException (void response) preview)
628− , httpConfigRetryPolicy = def
629− , httpConfigRetryJudge = \_ response ->
630− statusCode response `elem`
631− [ 408 -- Request timeout
632− , 504 -- Gateway timeout
633− , 524 -- A timeout occurred
634− , 598 -- (Informal convention) Network read timeout error
635− , 599 -- (Informal convention) Network connect timeout error
636− ]
637− }
638− where
639− statusCode = Y.statusCode . L.responseStatus
620+-- | Default value of 'HttpConfig'.
621+--
622+-- @since 2.0.0
623+
624+defaultHttpConfig :: HttpConfig
625+defaultHttpConfig = HttpConfig
626+ { httpConfigProxy = Nothing
627+ , httpConfigRedirectCount = 10
628+ , httpConfigAltManager = Nothing
629+ , httpConfigCheckResponse = \_ response preview ->
630+ let scode = statusCode response
631+ in if 200 <= scode && scode < 300
632+ then Nothing
633+ else Just (L.StatusCodeException (void response) preview)
634+ , httpConfigRetryPolicy = retryPolicyDefault
635+ , httpConfigRetryJudge = \_ response ->
636+ statusCode response `elem`
637+ [ 408 -- Request timeout
638+ , 504 -- Gateway timeout
639+ , 524 -- A timeout occurred
640+ , 598 -- (Informal convention) Network read timeout error
641+ , 599 -- (Informal convention) Network connect timeout error
642+ ]
643+ }
644+ where
645+ statusCode = Y.statusCode . L.responseStatus
640646
641647instance RequestComponent HttpConfig where
642648 getRequestMod HttpConfig {..} = Endo $ \x ->
README.md+1−2
@@ -20,13 +20,12 @@ module Main (main) where
2020
2121import Control.Monad.IO.Class
2222import Data.Aeson
23−import Data.Default.Class
2423import Network.HTTP.Req
2524
2625main :: IO ()
2726-- You can either make your monad an instance of 'MonadHttp', or use
2827-- 'runReq' in any IO-enabled monad without defining new instances.
29−main = runReq def $ do
28+main = runReq defaultHttpConfig $ do
3029 let payload = object
3130 [ "foo" .= (10 :: Int)
3231 , "bar" .= (20 :: Int) ]
httpbin-tests/Network/HTTP/ReqSpec.hs+3−4
@@ -13,7 +13,6 @@ import Control.Exception
1313import Control.Monad.Reader
1414import Control.Monad.Trans.Control
1515import Data.Aeson (Value (..), ToJSON (..), object, (.=))
16−import Data.Default.Class
1716import Data.Monoid ((<>))
1817import Data.Proxy
1918import Data.Text (Text)
@@ -41,7 +40,7 @@ spec = do
4140
4241 describe "exception throwing on non-2xx status codes (Req monad)" $
4342 it "throws indeed for non-2xx" $
44− asIO . runReq def $
43+ asIO . runReq defaultHttpConfig $
4544 liftBaseWith $ \run ->
4645 run (req GET (httpbin /: "foo") NoReqBody ignoreResponse mempty)
4746 `shouldThrow` selector404
@@ -322,14 +321,14 @@ instance MonadHttp IO where
322321-- response status codes.
323322
324323prepareForShit :: Req a -> IO a
325−prepareForShit = runReq def { httpConfigCheckResponse = noNoise }
324+prepareForShit = runReq defaultHttpConfig { httpConfigCheckResponse = noNoise }
326325 where
327326 noNoise _ _ _ = Nothing
328327
329328-- | Run request with such settings that it throws on any response.
330329
331330blindlyThrowing :: Req a -> IO a
332−blindlyThrowing = runReq def { httpConfigCheckResponse = doit }
331+blindlyThrowing = runReq defaultHttpConfig { httpConfigCheckResponse = doit }
333332 where
334333 doit _ _ = error "Oops!"
335334
pure-tests/Network/HTTP/ReqSpec.hs+3−3
@@ -14,9 +14,9 @@ module Network.HTTP.ReqSpec
1414where
1515
1616import Control.Exception (throwIO)
17+import Control.Retry
1718import Data.Aeson (ToJSON (..))
1819import Data.ByteString (ByteString)
19−import Data.Default.Class
2020import Data.Maybe (isNothing, fromJust)
2121import Data.Monoid ((<>))
2222import Data.Proxy
@@ -266,7 +266,7 @@ spec = do
266266 (oAuth2Bearer token0 <> oAuth2Bearer token1)
267267 lookup "Authorization" (L.requestHeaders request) `shouldBe`
268268 pure ("Bearer " <> token0)
269− describe "ProxyAuthorization" $ do
269+ describe "ProxyAuthorization" $
270270 it "sets Authorization header to correct value" $
271271 property $ \username password -> do
272272 request <- req_ GET url NoReqBody (basicProxyAuth username password)
@@ -326,7 +326,7 @@ instance Arbitrary HttpConfig where
326326 httpConfigRedirectCount <- arbitrary
327327 let httpConfigAltManager = Nothing
328328 httpConfigCheckResponse _ _ _ = Nothing
329− httpConfigRetryPolicy = def
329+ httpConfigRetryPolicy = retryPolicyDefault
330330 httpConfigRetryJudge _ _ = False
331331 return HttpConfig {..}
332332
req.cabal+3−5
@@ -1,5 +1,5 @@
11name: req
2−version: 1.2.1
2+version: 2.0.0
33cabal-version: 1.18
44tested-with: GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.4, GHC==8.6.3
55license: BSD3
@@ -34,14 +34,13 @@ library
3434 , bytestring >= 0.10.8 && < 0.11
3535 , case-insensitive >= 0.2 && < 1.3
3636 , connection >= 0.2.2 && < 0.3
37− , data-default-class
3837 , http-api-data >= 0.2 && < 0.5
3938 , http-client >= 0.5 && < 0.7
4039 , http-client-tls >= 0.3.2 && < 0.4
4140 , http-types >= 0.8 && < 10.0
4241 , monad-control >= 1.0 && < 1.1
4342 , mtl >= 2.0 && < 3.0
44− , retry >= 0.7 && < 0.8
43+ , retry >= 0.8 && < 0.9
4544 , text >= 0.2 && < 1.3
4645 , time >= 1.2 && < 1.9
4746 , transformers >= 0.4 && < 0.6
@@ -72,13 +71,13 @@ test-suite pure-tests
7271 , blaze-builder >= 0.3 && < 0.5
7372 , bytestring >= 0.10.8 && < 0.11
7473 , case-insensitive >= 0.2 && < 1.3
75− , data-default-class
7674 , hspec >= 2.0 && < 3.0
7775 , hspec-core >= 2.0 && < 3.0
7876 , http-client >= 0.5 && < 0.7
7977 , http-types >= 0.8 && < 10.0
8078 , mtl >= 2.0 && < 3.0
8179 , req
80+ , retry >= 0.8 && < 0.9
8281 , text >= 0.2 && < 1.3
8382 , time >= 1.2 && < 1.9
8483 build-tools: hspec-discover >= 2.0 && < 3.0
@@ -97,7 +96,6 @@ test-suite httpbin-tests
9796 , aeson >= 0.9 && < 1.5
9897 , base >= 4.8 && < 5.0
9998 , bytestring >= 0.10.8 && < 0.11
100− , data-default-class
10199 , hspec >= 2.0 && < 3.0
102100 , http-client >= 0.5 && < 0.7
103101 , http-types >= 0.8 && < 10.0