req 2.0.1 → 2.1.0
raw patch · 3 files changed
+38/−29 lines, 3 filesdep −semigroupsdep ~base
Dependencies removed: semigroups
Dependency ranges changed: base
Files
- CHANGELOG.md +8/−0
- Network/HTTP/Req.hs +23/−20
- req.cabal +7/−9
CHANGELOG.md view
@@ -1,3 +1,11 @@+## Req 2.1.0++* Dropped support for GHC 7.10.++* Added the new `acceptHeader` method to the `HttpResponse` type class.+ Notably, the `jsonResponse` method now sets `"Accept"` header to+ `"application/json"`.+ ## Req 2.0.1 * Fixed the `httpbin` tests (they changed something on the server again).
Network/HTTP/Req.hs view
@@ -89,7 +89,6 @@ -- @wreq@. The only difference is the API. {-# LANGUAGE BangPatterns #-}-{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-}@@ -102,15 +101,8 @@ {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-}--#if MIN_VERSION_base(4,9,0) {-# LANGUAGE UndecidableInstances #-}-#endif -#if __GLASGOW_HASKELL__ >= 800-{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}-#endif- module Network.HTTP.Req ( -- * Making a request -- $making-a-request@@ -217,6 +209,7 @@ import Control.Applicative import Control.Arrow (first, second)+import Control.Exception hiding (TypeError) import Control.Monad.Base import Control.Monad.IO.Class import Control.Monad.Reader@@ -227,6 +220,7 @@ import Data.Data (Data) import Data.Function (on) import Data.IORef+import Data.Kind (Constraint) import Data.List (nubBy) import Data.List.NonEmpty (NonEmpty (..)) import Data.Maybe (fromMaybe)@@ -255,14 +249,6 @@ import qualified Network.HTTP.Types as Y import qualified Web.Authenticate.OAuth as OAuth -#if MIN_VERSION_base(4,9,0)-import Control.Exception hiding (TypeError)-import Data.Kind (Constraint)-#else-import Control.Exception-import GHC.Exts (Constraint)-#endif- ---------------------------------------------------------------------------- -- Making a request @@ -311,6 +297,7 @@ -- First, this is a piece of boilerplate that should be in place before you -- try the examples: --+-- > {-# LANGUAGE DeriveGeneric #-} -- > {-# LANGUAGE OverloadedStrings #-} -- > -- > module Main (main) where@@ -403,8 +390,13 @@ -> Proxy response -- ^ A hint how to interpret response -> Option scheme -- ^ Collection of optional parameters -> m response -- ^ Response-req method url body Proxy options =- reqBr method url body options getHttpResponse+req method url body responseProxy options =+ reqBr method url body (options <> extraOptions) getHttpResponse+ where+ extraOptions =+ case acceptHeader responseProxy of+ Nothing -> mempty+ Just accept -> header "Accept" accept -- | A version of 'req' that does not use one of the predefined instances of -- 'HttpResponse' but instead allows the user to consume @'L.Response'@@ -1108,10 +1100,8 @@ (providesBody :: CanHaveBody) :: Constraint where HttpBodyAllowed 'NoBody 'NoBody = () HttpBodyAllowed 'CanHaveBody body = ()-#if MIN_VERSION_base(4,9,0) HttpBodyAllowed 'NoBody 'CanHaveBody = TypeError ('Text "This HTTP method does not allow attaching a request body.")-#endif instance HttpBody body => RequestComponent (Womb "body" body) where getRequestMod (Womb body) = Endo $ \x ->@@ -1454,6 +1444,7 @@ case A.eitherDecode (BL.fromChunks chunks) of Left e -> throwIO (JsonHttpException e) Right x -> return $ JsonResponse (x <$ r)+ acceptHeader Proxy = Just "application/json" -- | Use this as the fourth argument of 'req' to specify that you want it to -- return the 'JsonResponse' interpretation.@@ -1650,6 +1641,18 @@ -- ^ Response with body reader inside -> IO response -- ^ The final result++ -- | The value of @\"Accept\"@ header. This is useful, for example, if a+ -- website supports both @XML@ and @JSON@ responses, and decides what to+ -- reply with based on what @Accept@ headers you have sent.+ --+ -- __Note__: manually specified 'Options' that set the @\"Accept\"@ header+ -- will take precedence.+ --+ -- @since 2.1.0++ acceptHeader :: Proxy response -> Maybe ByteString+ acceptHeader Proxy = Nothing ---------------------------------------------------------------------------- -- Other
req.cabal view
@@ -1,7 +1,7 @@ name: req-version: 2.0.1+version: 2.1.0 cabal-version: 1.18-tested-with: GHC==7.10.3, GHC==8.0.2, GHC==8.2.2, GHC==8.4.4, GHC==8.6.3+tested-with: GHC==8.0.2, GHC==8.2.2, GHC==8.4.4, GHC==8.6.5 license: BSD3 license-file: LICENSE.md author: Mark Karpov <markkarpov92@gmail.com>@@ -29,11 +29,11 @@ library build-depends: aeson >= 0.9 && < 1.5 , authenticate-oauth >= 1.5 && < 1.7- , base >= 4.8 && < 5.0+ , base >= 4.9 && < 5.0 , blaze-builder >= 0.3 && < 0.5 , bytestring >= 0.10.8 && < 0.11 , case-insensitive >= 0.2 && < 1.3- , connection >= 0.2.2 && < 0.3+ , connection >= 0.2.2 && < 0.4 , http-api-data >= 0.2 && < 0.5 , http-client >= 0.5 && < 0.7 , http-client-tls >= 0.3.2 && < 0.4@@ -45,14 +45,12 @@ , time >= 1.2 && < 1.9 , transformers >= 0.4 && < 0.6 , transformers-base- if !impl(ghc >= 8.0)- build-depends: semigroups == 0.18.* exposed-modules: Network.HTTP.Req if flag(dev) ghc-options: -O0 -Wall -Werror else ghc-options: -O2 -Wall- if flag(dev) && impl(ghc >= 8.0)+ if flag(dev) ghc-options: -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns@@ -67,7 +65,7 @@ type: exitcode-stdio-1.0 build-depends: QuickCheck >= 2.7 && < 3.0 , aeson >= 0.9 && < 1.5- , base >= 4.8 && < 5.0+ , base >= 4.9 && < 5.0 , blaze-builder >= 0.3 && < 0.5 , bytestring >= 0.10.8 && < 0.11 , case-insensitive >= 0.2 && < 1.3@@ -94,7 +92,7 @@ type: exitcode-stdio-1.0 build-depends: QuickCheck >= 2.7 && < 3.0 , aeson >= 0.9 && < 1.5- , base >= 4.8 && < 5.0+ , base >= 4.9 && < 5.0 , bytestring >= 0.10.8 && < 0.11 , hspec >= 2.0 && < 3.0 , http-client >= 0.5 && < 0.7