on d97a634 help sign in
11 files changed+233−516
since splitsnapshots
unifiedsplit
.github/dependabot.yml−6 .github/workflows/ci.yaml+15−16 .gitignore−1 CHANGELOG.md−55 Network/HTTP/Req.hs+69−218 README.md+3−1 Setup.hs+6 cabal.project−4 httpbin-tests/Network/HTTP/ReqSpec.hs+60−103 pure-tests/Network/HTTP/ReqSpec.hs+21−53 req.cabal+59−59
.github/dependabot.ymldeleted−6
@@ -1,6 +0,0 @@
1−version: 2
2−updates:
3− - package-ecosystem: "github-actions"
4− directory: "/"
5− schedule:
6− interval: "weekly"
.github/workflows/ci.yaml+15−16
@@ -11,25 +11,27 @@ jobs:
1111 ormolu:
1212 runs-on: ubuntu-latest
1313 steps:
14− - uses: actions/checkout@v4
15− - uses: haskell-actions/run-ormolu@v17
14+ - uses: actions/checkout@v2.3.4
15+ - uses: mrkkrp/ormolu-action@v2
1616 build:
1717 runs-on: ubuntu-latest
1818 needs: ormolu
1919 strategy:
2020 matrix:
21− cabal: ["3.12"]
22− ghc: ["9.6.3", "9.8.2", "9.10.1"]
21+ cabal: ["3.4"]
22+ ghc: ["8.8.4", "8.10.4", "9.0.1"]
23+ env:
24+ CONFIG: "--enable-tests --enable-benchmarks --flags=dev"
2325 steps:
24− - uses: actions/checkout@v4
25− - uses: haskell-actions/setup@v2
26+ - uses: actions/checkout@v2.3.4
27+ - uses: haskell/actions/setup@v1.2
2628 id: setup-haskell-cabal
2729 with:
2830 ghc-version: ${{ matrix.ghc }}
2931 cabal-version: ${{ matrix.cabal }}
30− - run: cabal update
31− - run: cabal freeze
32− - uses: actions/cache@v4.2.3
32+ - run: cabal v2-update
33+ - run: cabal v2-freeze $CONFIG
34+ - uses: actions/cache@v2.1.3
3335 with:
3436 path: |
3537 ${{ steps.setup-haskell-cabal.outputs.cabal-store }}
@@ -38,10 +40,7 @@ jobs:
3840 restore-keys: |
3941 ${{ runner.os }}-${{ matrix.ghc }}-
4042 - run: cabal format && git diff --exit-code --color=always
41− - run: cabal build
42− - run: |
43− docker pull kennethreitz/httpbin
44− docker run -p 1234:80 kennethreitz/httpbin &
45− cabal test
46− - run: cabal haddock
47− - run: cabal sdist
43+ - run: cabal v2-build $CONFIG
44+ - run: cabal v2-test $CONFIG
45+ - run: cabal v2-haddock $CONFIG
46+ - run: cabal v2-sdist
.gitignore−1
@@ -25,6 +25,5 @@ cabal.project.local
2525cabal.sandbox.config
2626dist-*/
2727dist/
28−hie.yaml
2928stack.yaml
3029stack.yaml.lock
CHANGELOG.md−55
@@ -1,58 +1,3 @@
1−## Req 3.13.4
2−
3−* Fixed empty ciphersuite list when compiling against `tls < 2.0.6`
4− (see [PR 175](https://github.com/mrkkrp/req/pull/175)). As a side effect, now
5− compatible with older versions of `crypton-connection` (>= 0.3).
6−
7−## Req 3.13.3
8−
9−* Works with `crypton-connection-0.4` and newer.
10−
11−## Req 3.13.2
12−
13−* Disable the problematic `httpbin-tests` test suite by default. Only enable
14− it when the `dev` flag is enabled. In that case it is expected that an
15− httpbin server is run locally at `localhost:1234`.
16−
17−## Req 3.13.1
18−
19−* Switched the non-pure test suite to use https://httpbun.org instead of
20− https://httpbin.org since the latter proved to be highly unreliable
21− lately.
22−
23−* Switched from `connection` to `crypton-connection`.
24−
25−* Builds with GHC 9.6.1.
26−
27−## Req 3.13.0
28−
29−* Add `headerRedacted` function to add header fields, which will be with
30− redacted values on print.
31−
32−## Req 3.12.0
33−
34−* Add `isStatusCodeException` function.
35−* Add `instance HttpResponse (Network.HTTP.Client.Response ())`.
36−
37−## Req 3.11.0
38−
39−* Add the `queryParamToList` method to the `QueryParam` type class.
40−* Add the `formToQuery` function. [Issue 126](https://github.com/mrkkrp/req/issues/126).
41−* Add `FromForm` instances (in the `Web.FormUrlEncoded` module) to the
42− `Option` and `FormUrlEncodedParam` types.
43−
44−## Req 3.10.0
45−
46−* Add `MonadHttp` instances for `transformers` types.
47−
48−## Req 3.9.2
49−
50−* The test suite works with `aeson-2.x.x.x`.
51−
52−## Req 3.9.1
53−
54−* Builds with GHC 9.0.
55−
561## Req 3.9.0
572
583* The `useHttpURI` and `useHttpsURI` functions now preserve trailing
Network/HTTP/Req.hs+69−218
@@ -1,9 +1,20 @@
1+{-# LANGUAGE BangPatterns #-}
2+{-# LANGUAGE CPP #-}
13{-# LANGUAGE DataKinds #-}
4+{-# LANGUAGE DeriveDataTypeable #-}
5+{-# LANGUAGE DeriveGeneric #-}
6+{-# LANGUAGE DeriveLift #-}
7+{-# LANGUAGE FlexibleInstances #-}
8+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
29{-# LANGUAGE LambdaCase #-}
10+{-# LANGUAGE MultiParamTypeClasses #-}
311{-# LANGUAGE OverloadedStrings #-}
412{-# LANGUAGE QuasiQuotes #-}
13+{-# LANGUAGE RankNTypes #-}
514{-# LANGUAGE RecordWildCards #-}
615{-# LANGUAGE RoleAnnotations #-}
16+{-# LANGUAGE ScopedTypeVariables #-}
17+{-# LANGUAGE StandaloneDeriving #-}
718{-# LANGUAGE TemplateHaskellQuotes #-}
819{-# LANGUAGE TypeFamilies #-}
920{-# LANGUAGE UndecidableInstances #-}
@@ -144,13 +155,11 @@ module Network.HTTP.Req
144155 -- $query-parameters
145156 (=:),
146157 queryFlag,
147− formToQuery,
148158 QueryParam (..),
149159
150160 -- *** Headers
151161 header,
152162 attachHeader,
153− headerRedacted,
154163
155164 -- *** Cookies
156165 -- $cookies
@@ -197,78 +206,58 @@ module Network.HTTP.Req
197206
198207 -- * Other
199208 HttpException (..),
200− isStatusCodeException,
201209 CanHaveBody (..),
202210 Scheme (..),
203211 )
204212where
205213
206−import Blaze.ByteString.Builder qualified as BB
214+import qualified Blaze.ByteString.Builder as BB
207215import Control.Applicative
208216import Control.Arrow (first, second)
209217import Control.Exception hiding (Handler (..), TypeError)
210−import Control.Monad (guard, void, (>=>))
211218import Control.Monad.Base
212219import Control.Monad.Catch (Handler (..), MonadCatch, MonadMask, MonadThrow)
213220import Control.Monad.IO.Class
214221import Control.Monad.IO.Unlift
215−import Control.Monad.Reader (ReaderT (ReaderT), ask, lift, runReaderT)
216−import Control.Monad.Trans.Accum (AccumT)
217−import Control.Monad.Trans.Cont (ContT)
222+import Control.Monad.Reader
218223import Control.Monad.Trans.Control
219−import Control.Monad.Trans.Except (ExceptT)
220−import Control.Monad.Trans.Identity (IdentityT)
221−import Control.Monad.Trans.Maybe (MaybeT)
222−import Control.Monad.Trans.RWS.CPS qualified as RWS.CPS
223−import Control.Monad.Trans.RWS.Lazy qualified as RWS.Lazy
224−import Control.Monad.Trans.RWS.Strict qualified as RWS.Strict
225−import Control.Monad.Trans.Select (SelectT)
226−import Control.Monad.Trans.State.Lazy qualified as State.Lazy
227−import Control.Monad.Trans.State.Strict qualified as State.Strict
228−import Control.Monad.Trans.Writer.CPS qualified as Writer.CPS
229−import Control.Monad.Trans.Writer.Lazy qualified as Writer.Lazy
230−import Control.Monad.Trans.Writer.Strict qualified as Writer.Strict
231224import Control.Retry
232225import Data.Aeson (FromJSON (..), ToJSON (..))
233−import Data.Aeson qualified as A
226+import qualified Data.Aeson as A
234227import Data.ByteString (ByteString)
235−import Data.ByteString qualified as B
236−import Data.ByteString.Lazy qualified as BL
237−import Data.CaseInsensitive qualified as CI
228+import qualified Data.ByteString as B
229+import qualified Data.ByteString.Lazy as BL
230+import qualified Data.CaseInsensitive as CI
238231import Data.Data (Data)
239−import Data.Default.Class (def)
240232import Data.Function (on)
241233import Data.IORef
242234import Data.Kind (Constraint, Type)
243235import Data.List (foldl', nubBy)
244236import Data.List.NonEmpty (NonEmpty (..))
245−import Data.List.NonEmpty qualified as NE
237+import qualified Data.List.NonEmpty as NE
246238import Data.Maybe (fromMaybe)
247239import Data.Proxy
248−import Data.Semigroup (Endo (..))
249−import Data.Set qualified as S
240+import Data.Semigroup hiding (Option, option)
250241import Data.Text (Text)
251−import Data.Text qualified as T
252−import Data.Text.Encoding qualified as T
242+import qualified Data.Text as T
243+import qualified Data.Text.Encoding as T
253244import Data.Typeable (Typeable, cast)
254245import GHC.Generics
255246import GHC.TypeLits
256−import Language.Haskell.TH qualified as TH
257−import Language.Haskell.TH.Quote qualified as TH
258−import Language.Haskell.TH.Syntax qualified as TH
259−import Network.Connection qualified as NC
260−import Network.HTTP.Client qualified as L
261−import Network.HTTP.Client.Internal qualified as LI
262−import Network.HTTP.Client.MultipartFormData qualified as LM
263−import Network.HTTP.Client.TLS qualified as L
264−import Network.HTTP.Types qualified as Y
247+import qualified Language.Haskell.TH as TH
248+import qualified Language.Haskell.TH.Quote as TH
249+import qualified Language.Haskell.TH.Syntax as TH
250+import qualified Network.Connection as NC
251+import qualified Network.HTTP.Client as L
252+import qualified Network.HTTP.Client.Internal as LI
253+import qualified Network.HTTP.Client.MultipartFormData as LM
254+import qualified Network.HTTP.Client.TLS as L
255+import qualified Network.HTTP.Types as Y
265256import System.IO.Unsafe (unsafePerformIO)
266257import Text.URI (URI)
267−import Text.URI qualified as URI
268−import Text.URI.QQ qualified as QQ
269−import Web.Authenticate.OAuth qualified as OAuth
270−import Web.FormUrlEncoded (FromForm (..), ToForm (..))
271−import Web.FormUrlEncoded qualified as Form
258+import qualified Text.URI as URI
259+import qualified Text.URI.QQ as QQ
260+import qualified Web.Authenticate.OAuth as OAuth
272261import Web.HttpApiData (ToHttpApiData (..))
273262
274263----------------------------------------------------------------------------
@@ -489,7 +478,7 @@ reqCb method url body responseProxy options adjustRequest =
489478--
490479-- @since 3.7.0
491480reqHandler ::
492− (MonadHttp m) =>
481+ MonadHttp m =>
493482 -- | How to get final result from a 'L.Response'
494483 (L.Response L.BodyReader -> IO b) ->
495484 -- | 'L.Request' to perform
@@ -585,10 +574,10 @@ req' method url body options m = do
585574 withReqManager (m request)
586575
587576-- | Perform an action using the global implicit 'L.Manager' that the rest
588−-- of the library uses. This allows us to reuse connections that the
577+-- of the library uses. This allows to reuse connections that the
589578-- 'L.Manager' controls.
590−withReqManager :: (MonadIO m) => (L.Manager -> m a) -> m a
591−withReqManager m = m globalManager
579+withReqManager :: MonadIO m => (L.Manager -> m a) -> m a
580+withReqManager m = liftIO (readIORef globalManager) >>= m
592581
593582-- | The global 'L.Manager' that 'req' uses. Here we just go with the
594583-- default settings, so users don't need to deal with this manager stuff at
@@ -601,16 +590,16 @@ withReqManager m = m globalManager
601590-- manager. From that moment on the 'IORef' will be just reused—exactly the
602591-- behavior we want here in order to maximize connection sharing. GHC could
603592-- spoil the plan by inlining the definition, hence the @NOINLINE@ pragma.
604−globalManager :: L.Manager
593+globalManager :: IORef L.Manager
605594globalManager = unsafePerformIO $ do
606595 context <- NC.initConnectionContext
607596 let settings =
608597 L.mkManagerSettingsContext
609598 (Just context)
610− def
599+ (NC.TLSSettingsSimple False False False)
611600 Nothing
612601 manager <- L.newManager settings
613− return manager
602+ newIORef manager
614603{-# NOINLINE globalManager #-}
615604
616605----------------------------------------------------------------------------
@@ -630,7 +619,7 @@ globalManager = unsafePerformIO $ do
630619-- | A type class for monads that support performing HTTP requests.
631620-- Typically, you only need to define the 'handleHttpException' method
632621-- unless you want to tweak 'HttpConfig'.
633−class (MonadIO m) => MonadHttp m where
622+class MonadIO m => MonadHttp m where
634623 -- | This method describes how to deal with 'HttpException' that was
635624 -- caught by the library. One option is to re-throw it if you are OK with
636625 -- exceptions, but if you prefer working with something like
@@ -691,8 +680,8 @@ data HttpConfig = HttpConfig
691680 -- | The retry policy to use for request retrying. By default 'def' is
692681 -- used (see 'RetryPolicyM').
693682 --
694− -- __Note__: signature of this function was changed to disallow 'IO' in
695− -- version /1.0.0/ and then changed back to its current form in /3.1.0/.
683+ -- __Note__: signature of this function was changed in the version
684+ -- /1.0.0/.
696685 --
697686 -- @since 0.3.0
698687 httpConfigRetryPolicy :: RetryPolicyM IO,
@@ -714,8 +703,9 @@ data HttpConfig = HttpConfig
714703 -- | Max length of preview fragment of response body.
715704 --
716705 -- @since 3.6.0
717− httpConfigBodyPreviewLength :: forall a. (Num a) => a
706+ httpConfigBodyPreviewLength :: forall a. Num a => a
718707 }
708+ deriving (Typeable)
719709
720710-- | The default value of 'HttpConfig'.
721711--
@@ -797,87 +787,12 @@ instance MonadHttp Req where
797787 handleHttpException = Req . lift . throwIO
798788 getHttpConfig = Req ask
799789
800−-- | @since 3.10.0
801−instance (MonadHttp m, Monoid w) => MonadHttp (AccumT w m) where
802− handleHttpException = lift . handleHttpException
803− getHttpConfig = lift getHttpConfig
804−
805−-- | @since 3.10.0
806−instance (MonadHttp m) => MonadHttp (ContT r m) where
807− handleHttpException = lift . handleHttpException
808− getHttpConfig = lift getHttpConfig
809−
810−-- | @since 3.10.0
811−instance (MonadHttp m) => MonadHttp (ExceptT e m) where
812− handleHttpException = lift . handleHttpException
813− getHttpConfig = lift getHttpConfig
814−
815−-- | @since 3.10.0
816−instance (MonadHttp m) => MonadHttp (IdentityT m) where
817− handleHttpException = lift . handleHttpException
818− getHttpConfig = lift getHttpConfig
819−
820−-- | @since 3.10.0
821−instance (MonadHttp m) => MonadHttp (MaybeT m) where
822− handleHttpException = lift . handleHttpException
823− getHttpConfig = lift getHttpConfig
824−
825−-- | @since 3.10.0
826−instance (MonadHttp m) => MonadHttp (ReaderT r m) where
827− handleHttpException = lift . handleHttpException
828− getHttpConfig = lift getHttpConfig
829−
830−-- | @since 3.10.0
831−instance (MonadHttp m, Monoid w) => MonadHttp (RWS.CPS.RWST r w s m) where
832− handleHttpException = lift . handleHttpException
833− getHttpConfig = lift getHttpConfig
834−
835−-- | @since 3.10.0
836−instance (MonadHttp m, Monoid w) => MonadHttp (RWS.Lazy.RWST r w s m) where
837− handleHttpException = lift . handleHttpException
838− getHttpConfig = lift getHttpConfig
839−
840−-- | @since 3.10.0
841−instance (MonadHttp m, Monoid w) => MonadHttp (RWS.Strict.RWST r w s m) where
842− handleHttpException = lift . handleHttpException
843− getHttpConfig = lift getHttpConfig
844−
845−-- | @since 3.10.0
846−instance (MonadHttp m) => MonadHttp (SelectT r m) where
847− handleHttpException = lift . handleHttpException
848− getHttpConfig = lift getHttpConfig
849−
850−-- | @since 3.10.0
851−instance (MonadHttp m) => MonadHttp (State.Lazy.StateT s m) where
852− handleHttpException = lift . handleHttpException
853− getHttpConfig = lift getHttpConfig
854−
855−-- | @since 3.10.0
856−instance (MonadHttp m) => MonadHttp (State.Strict.StateT s m) where
857− handleHttpException = lift . handleHttpException
858− getHttpConfig = lift getHttpConfig
859−
860−-- | @since 3.10.0
861−instance (MonadHttp m, Monoid w) => MonadHttp (Writer.CPS.WriterT w m) where
862− handleHttpException = lift . handleHttpException
863− getHttpConfig = lift getHttpConfig
864−
865−-- | @since 3.10.0
866−instance (MonadHttp m, Monoid w) => MonadHttp (Writer.Lazy.WriterT w m) where
867− handleHttpException = lift . handleHttpException
868− getHttpConfig = lift getHttpConfig
869−
870−-- | @since 3.10.0
871−instance (MonadHttp m, Monoid w) => MonadHttp (Writer.Strict.WriterT w m) where
872− handleHttpException = lift . handleHttpException
873− getHttpConfig = lift getHttpConfig
874−
875790-- | Run a computation in the 'Req' monad with the given 'HttpConfig'. In
876791-- the case of an exceptional situation an 'HttpException' will be thrown.
877792--
878793-- @since 0.4.0
879794runReq ::
880− (MonadIO m) =>
795+ MonadIO m =>
881796 -- | 'HttpConfig' to use
882797 HttpConfig ->
883798 -- | Computation to run
@@ -982,7 +897,7 @@ class HttpMethod a where
982897 -- | Return name of the method as a 'ByteString'.
983898 httpMethodName :: Proxy a -> ByteString
984899
985−instance (HttpMethod method) => RequestComponent (Tagged "method" method) where
900+instance HttpMethod method => RequestComponent (Tagged "method" method) where
986901 getRequestMod _ = Endo $ \x ->
987902 x {L.method = httpMethodName (Proxy :: Proxy method)}
988903
@@ -1024,20 +939,25 @@ instance (HttpMethod method) => RequestComponent (Tagged "method" method) where
1024939-- > -- https://%D1%8E%D0%BD%D0%B8%D0%BA%D0%BE%D0%B4.%D1%80%D1%84
1025940data Url (scheme :: Scheme) = Url Scheme (NonEmpty Text)
1026941 -- NOTE The second value is the path segments in reversed order.
1027− deriving (Eq, Ord, Show, Data, Generic)
942+ deriving (Eq, Ord, Show, Data, Typeable, Generic)
1028943
1029944type role Url nominal
1030945
1031946-- With template-haskell >=2.15 and text >=1.2.4 Lift can be derived, however
1032947-- the derived lift forgets the type of the scheme.
1033−instance (Typeable scheme) => TH.Lift (Url scheme) where
948+instance Typeable scheme => TH.Lift (Url scheme) where
1034949 lift url =
1035950 TH.dataToExpQ (fmap liftText . cast) url `TH.sigE` case url of
1036951 Url Http _ -> [t|Url 'Http|]
1037952 Url Https _ -> [t|Url 'Https|]
1038953 where
1039954 liftText t = TH.AppE (TH.VarE 'T.pack) <$> TH.lift (T.unpack t)
955+
956+#if MIN_VERSION_template_haskell(2,17,0)
1040957 liftTyped = TH.Code . TH.unsafeTExpCoerce . TH.lift
958+#elif MIN_VERSION_template_haskell(2,16,0)
959+ liftTyped = TH.unsafeTExpCoerce . TH.lift
960+#endif
1041961
1042962-- | Given host name, produce a 'Url' which has “http” as its scheme and
1043963-- empty path. This also sets port to @80@.
@@ -1053,7 +973,7 @@ https = Url Https . pure
1053973-- path segment can be of any type that is an instance of 'ToHttpApiData'.
1054974infixl 5 /~
1055975
1056−(/~) :: (ToHttpApiData a) => Url scheme -> a -> Url scheme
976+(/~) :: ToHttpApiData a => Url scheme -> a -> Url scheme
1057977Url secure path /~ segment = Url secure (NE.cons (toUrlPiece segment) path)
1058978
1059979-- | A type-constrained version of @('/~')@ to remove ambiguity in the cases
@@ -1241,7 +1161,7 @@ instance HttpBody NoReqBody where
12411161-- charset=utf-8\"@ value.
12421162newtype ReqBodyJson a = ReqBodyJson a
12431163
1244−instance (ToJSON a) => HttpBody (ReqBodyJson a) where
1164+instance ToJSON a => HttpBody (ReqBodyJson a) where
12451165 getRequestBody (ReqBodyJson a) = L.RequestBodyLBS (A.encode a)
12461166 getRequestContentType _ = pure "application/json; charset=utf-8"
12471167
@@ -1294,13 +1214,6 @@ newtype FormUrlEncodedParam = FormUrlEncodedParam [(Text, Maybe Text)]
12941214instance QueryParam FormUrlEncodedParam where
12951215 queryParam name mvalue =
12961216 FormUrlEncodedParam [(name, toQueryParam <$> mvalue)]
1297− queryParamToList (FormUrlEncodedParam p) = p
1298−
1299−-- | Use 'formToQuery'.
1300−--
1301−-- @since 3.11.0
1302−instance FromForm FormUrlEncodedParam where
1303− fromForm = Right . formToQuery
13041217
13051218-- | Multipart form data. Please consult the
13061219-- "Network.HTTP.Client.MultipartFormData" module for how to construct
@@ -1340,7 +1253,7 @@ instance HttpBody ReqBodyMultipart where
13401253-- | Create 'ReqBodyMultipart' request body from a collection of 'LM.Part's.
13411254--
13421255-- @since 0.2.0
1343−reqBodyMultipart :: (MonadIO m) => [LM.Part] -> m ReqBodyMultipart
1256+reqBodyMultipart :: MonadIO m => [LM.Part] -> m ReqBodyMultipart
13441257reqBodyMultipart parts = liftIO $ do
13451258 boundary <- LM.webkitBoundary
13461259 body <- LM.renderParts boundary parts
@@ -1380,7 +1293,7 @@ type family
13801293 TypeError
13811294 ('Text "This HTTP method does not allow attaching a request body.")
13821295
1383−instance (HttpBody body) => RequestComponent (Tagged "body" body) where
1296+instance HttpBody body => RequestComponent (Tagged "body" body) where
13841297 getRequestMod (Tagged body) = Endo $ \x ->
13851298 x
13861299 { L.requestBody = getRequestBody body,
@@ -1426,12 +1339,6 @@ instance Monoid (Option scheme) where
14261339 mempty = Option mempty Nothing
14271340 mappend = (<>)
14281341
1429−-- | Use 'formToQuery'.
1430−--
1431−-- @since 3.11.0
1432−instance FromForm (Option scheme) where
1433− fromForm = Right . formToQuery
1434−
14351342-- | A helper to create an 'Option' that modifies only collection of query
14361343-- parameters. This helper is not a part of the public API.
14371344withQueryParams :: (Y.QueryText -> Y.QueryText) -> Option scheme
@@ -1450,7 +1357,7 @@ instance RequestComponent (Option scheme) where
14501357
14511358-- | Finalize given 'L.Request' by applying a finalizer from the given
14521359-- 'Option' (if it has any).
1453−finalizeRequest :: (MonadIO m) => Option scheme -> L.Request -> m L.Request
1360+finalizeRequest :: MonadIO m => Option scheme -> L.Request -> m L.Request
14541361finalizeRequest (Option _ mfinalizer) = liftIO . fromMaybe pure mfinalizer
14551362
14561363----------------------------------------------------------------------------
@@ -1483,27 +1390,9 @@ name =: value = queryParam name (pure value)
14831390-- This operator is defined in terms of 'queryParam':
14841391--
14851392-- > queryFlag name = queryParam name (Nothing :: Maybe ())
1486−queryFlag :: (QueryParam param) => Text -> param
1393+queryFlag :: QueryParam param => Text -> param
14871394queryFlag name = queryParam name (Nothing :: Maybe ())
14881395
1489−-- | Construct query parameters from a 'ToForm' instance. This function
1490−-- produces the same query params as 'Form.urlEncodeAsFormStable'.
1491−--
1492−-- Note that 'Form.Form' doesn't have the concept of parameters with the
1493−-- empty value (i.e. what you can get by @key =: ""@). If the value is
1494−-- empty, it will be encoded as a valueless parameter (i.e. what you can get
1495−-- by @queryFlag key@).
1496−--
1497−-- @since 3.11.0
1498−formToQuery :: (QueryParam param, Monoid param, ToForm f) => f -> param
1499−formToQuery f = mconcat . fmap toParam . Form.toListStable $ toForm f
1500− where
1501− toParam (key, val) =
1502− queryParam key $
1503− if val == ""
1504− then Nothing
1505− else Just val
1506−
15071396-- | A type class for query-parameter-like things. The reason to have an
15081397-- overloaded 'queryParam' is to be able to use it as an 'Option' and as a
15091398-- 'FormUrlEncodedParam' when constructing form URL encoded request bodies.
@@ -1513,17 +1402,11 @@ class QueryParam param where
15131402 -- 'Nothing', it won't be included at all (i.e. you create a flag this
15141403 -- way). It's recommended to use @('=:')@ and 'queryFlag' instead of this
15151404 -- method, because they are easier to read.
1516− queryParam :: (ToHttpApiData a) => Text -> Maybe a -> param
1517−
1518− -- | Get the query parameter names and values set by 'queryParam'.
1519− --
1520− -- @since 3.11.0
1521− queryParamToList :: param -> [(Text, Maybe Text)]
1405+ queryParam :: ToHttpApiData a => Text -> Maybe a -> param
15221406
15231407instance QueryParam (Option scheme) where
15241408 queryParam name mvalue =
15251409 withQueryParams ((:) (name, toQueryParam <$> mvalue))
1526− queryParamToList (Option f _) = fst $ appEndo f ([], L.defaultRequest)
15271410
15281411----------------------------------------------------------------------------
15291412-- Request—Optional parameters—Headers
@@ -1547,14 +1430,6 @@ attachHeader :: ByteString -> ByteString -> L.Request -> L.Request
15471430attachHeader name value x =
15481431 x {L.requestHeaders = (CI.mk name, value) : L.requestHeaders x}
15491432
1550−-- | Same as 'header', but with redacted values on print.
1551−--
1552−-- @since 3.13.0
1553−headerRedacted :: ByteString -> ByteString -> Option scheme
1554−headerRedacted name value = withRequest $ \x ->
1555− let y = attachHeader name value x
1556− in y {L.redactHeaders = CI.mk name `S.insert` L.redactHeaders y}
1557−
15581433----------------------------------------------------------------------------
15591434-- Request—Optional parameters—Cookies
15601435
@@ -1762,7 +1637,7 @@ ignoreResponse = Proxy
17621637newtype JsonResponse a = JsonResponse (L.Response a)
17631638 deriving (Show)
17641639
1765−instance (FromJSON a) => HttpResponse (JsonResponse a) where
1640+instance FromJSON a => HttpResponse (JsonResponse a) where
17661641 type HttpResponseBody (JsonResponse a) = a
17671642 toVanillaResponse (JsonResponse r) = r
17681643 getHttpResponse r = do
@@ -1878,14 +1753,14 @@ brReadN br n = go 0 id id
18781753
18791754-- | Get the response body.
18801755responseBody ::
1881− (HttpResponse response) =>
1756+ HttpResponse response =>
18821757 response ->
18831758 HttpResponseBody response
18841759responseBody = L.responseBody . toVanillaResponse
18851760
18861761-- | Get the response status code.
18871762responseStatusCode ::
1888− (HttpResponse response) =>
1763+ HttpResponse response =>
18891764 response ->
18901765 Int
18911766responseStatusCode =
@@ -1893,7 +1768,7 @@ responseStatusCode =
18931768
18941769-- | Get the response status message.
18951770responseStatusMessage ::
1896− (HttpResponse response) =>
1771+ HttpResponse response =>
18971772 response ->
18981773 ByteString
18991774responseStatusMessage =
@@ -1901,7 +1776,7 @@ responseStatusMessage =
19011776
19021777-- | Lookup a particular header from a response.
19031778responseHeader ::
1904− (HttpResponse response) =>
1779+ HttpResponse response =>
19051780 -- | Response interpretation
19061781 response ->
19071782 -- | Header to lookup
@@ -1913,7 +1788,7 @@ responseHeader r h =
19131788
19141789-- | Get the response 'L.CookieJar'.
19151790responseCookieJar ::
1916− (HttpResponse response) =>
1791+ HttpResponse response =>
19171792 response ->
19181793 L.CookieJar
19191794responseCookieJar = L.responseCookieJar . toVanillaResponse
@@ -1967,16 +1842,6 @@ class HttpResponse response where
19671842 acceptHeader :: Proxy response -> Maybe ByteString
19681843 acceptHeader Proxy = Nothing
19691844
1970−-- | This instance has been added to make it easier to inspect 'L.Response'
1971−-- using Req's functions like 'responseStatusCode', 'responseStatusMessage',
1972−-- etc.
1973−--
1974−-- @since 3.12.0
1975−instance HttpResponse (L.Response ()) where
1976− type HttpResponseBody (L.Response ()) = ()
1977− toVanillaResponse = id
1978− getHttpResponse = return . void
1979−
19801845----------------------------------------------------------------------------
19811846-- Other
19821847
@@ -2011,24 +1876,10 @@ data HttpException
20111876 | -- | A wrapper with Aeson-produced 'String' describing why decoding
20121877 -- failed
20131878 JsonHttpException String
2014− deriving (Show, Generic)
1879+ deriving (Show, Typeable, Generic)
20151880
20161881instance Exception HttpException
20171882
2018−-- | Return 'Just' if the given 'HttpException' is wrapping a http-client's
2019−-- 'L.StatusCodeException'. Otherwise, return 'Nothing'.
2020−--
2021−-- @since 3.12.0
2022−isStatusCodeException :: HttpException -> Maybe (L.Response ())
2023−isStatusCodeException
2024− ( VanillaHttpException
2025− ( L.HttpExceptionRequest
2026− _
2027− (L.StatusCodeException r _)
2028− )
2029− ) = Just r
2030−isStatusCodeException _ = Nothing
2031−
20321883-- | A simple type isomorphic to 'Bool' that we only have for better error
20331884-- messages. We use it as a kind and its data constructors as type-level
20341885-- tags.
@@ -2048,4 +1899,4 @@ data Scheme
20481899 Http
20491900 | -- | HTTPS
20501901 Https
2051− deriving (Eq, Ord, Show, Data, Generic, TH.Lift)
1902+ deriving (Eq, Ord, Show, Data, Typeable, Generic, TH.Lift)
README.md+3−1
@@ -4,8 +4,10 @@
44[![Hackage](https://img.shields.io/hackage/v/req.svg?style=flat)](https://hackage.haskell.org/package/req)
55[![Stackage Nightly](http://stackage.org/package/req/badge/nightly)](http://stackage.org/nightly/package/req)
66[![Stackage LTS](http://stackage.org/package/req/badge/lts)](http://stackage.org/lts/package/req)
7−[![CI](https://github.com/mrkkrp/req/actions/workflows/ci.yaml/badge.svg)](https://github.com/mrkkrp/req/actions/workflows/ci.yaml)
7+![CI](https://github.com/mrkkrp/req/workflows/CI/badge.svg?branch=master)
88
9+* [Motivation and Req vs other libraries](#motivation-and-req-vs-other-libraries)
10+* [Unsolved problems](#unsolved-problems)
911* [Related packages](#related-packages)
1012* [Blog posts](#blog-posts)
1113* [Contribution](#contribution)
Setup.hsnew file+6
@@ -0,0 +1,6 @@
1+module Main (main) where
2+
3+import Distribution.Simple
4+
5+main :: IO ()
6+main = defaultMain
cabal.projectdeleted−4
@@ -1,4 +0,0 @@
1−packages: .
2−tests: True
3−benchmarks: True
4−constraints: req +dev
httpbin-tests/Network/HTTP/ReqSpec.hs+60−103
@@ -1,6 +1,5 @@
11{-# LANGUAGE DataKinds #-}
22{-# LANGUAGE FlexibleInstances #-}
3−{-# LANGUAGE LambdaCase #-}
43{-# LANGUAGE OverloadedStrings #-}
54{-# LANGUAGE RankNTypes #-}
65{-# OPTIONS_GHC -fno-warn-orphans #-}
@@ -8,25 +7,22 @@
87module Network.HTTP.ReqSpec (spec) where
98
109import Control.Exception
11−import Control.Monad (forM_)
10+import Control.Monad.Reader
1211import Control.Monad.Trans.Control
1312import Data.Aeson (ToJSON (..), Value (..), object, (.=))
14−import Data.Aeson qualified as A
15−import Data.Aeson.KeyMap qualified as Aeson.KeyMap
16−import Data.ByteString qualified as B
17−import Data.ByteString.Lazy qualified as BL
18−import Data.Functor.Identity (runIdentity)
19−import Data.Maybe (fromJust)
13+import qualified Data.Aeson as A
14+import qualified Data.ByteString as B
15+import qualified Data.ByteString.Lazy as BL
16+import qualified Data.HashMap.Strict as HM
2017import Data.Proxy
2118import Data.Text (Text)
22−import Data.Text qualified as T
23−import Data.Text.Encoding qualified as T
24−import Data.Text.IO qualified as TIO
25−import Network.HTTP.Client qualified as L
26−import Network.HTTP.Client.MultipartFormData qualified as LM
27−import Network.HTTP.Req hiding (req)
28−import Network.HTTP.Req qualified as Req
29−import Network.HTTP.Types qualified as Y
19+import qualified Data.Text as T
20+import qualified Data.Text.Encoding as T
21+import qualified Data.Text.IO as TIO
22+import qualified Network.HTTP.Client as L
23+import qualified Network.HTTP.Client.MultipartFormData as LM
24+import Network.HTTP.Req
25+import qualified Network.HTTP.Types as Y
3026import Test.Hspec
3127import Test.QuickCheck
3228
@@ -50,11 +46,6 @@ spec = do
5046 blindlyThrowing (req GET httpbin NoReqBody ignoreResponse mempty)
5147 `shouldThrow` anyException
5248
53− describe "isStatusCodeException" $
54− it "extracts non-2xx response" $
55− req GET (httpbin /: "foo") NoReqBody ignoreResponse mempty
56− `shouldThrow` selector404ByStatusCodeException
57−
5849 describe "receiving user-agent header back" $
5950 it "works" $ do
6051 r <-
@@ -85,7 +76,8 @@ spec = do
8576 .= object
8677 [ "Accept-Encoding" .= ("gzip" :: Text),
8778 "Foo" .= ("bar" :: Text),
88− "Baz" .= ("quux" :: Text)
79+ "Baz" .= ("quux" :: Text),
80+ "Host" .= ("httpbin.org" :: Text)
8981 ]
9082 ]
9183 responseStatusCode r `shouldBe` 200
@@ -97,10 +89,11 @@ spec = do
9789 (stripFunnyHeaders . stripOrigin) (responseBody r)
9890 `shouldBe` object
9991 [ "args" .= emptyObject,
100− "url" .= ("http://localhost:1234/get" :: Text),
92+ "url" .= ("https://httpbin.org/get" :: Text),
10193 "headers"
10294 .= object
103− [ "Accept-Encoding" .= ("gzip" :: Text)
95+ [ "Accept-Encoding" .= ("gzip" :: Text),
96+ "Host" .= ("httpbin.org" :: Text)
10497 ]
10598 ]
10699 responseHeader r "Content-Type" `shouldBe` return "application/json"
@@ -117,11 +110,12 @@ spec = do
117110 [ "args" .= emptyObject,
118111 "json" .= text,
119112 "data" .= reflected,
120− "url" .= ("http://localhost:1234/post" :: Text),
113+ "url" .= ("https://httpbin.org/post" :: Text),
121114 "headers"
122115 .= object
123116 [ "Content-Type" .= ("application/json; charset=utf-8" :: Text),
124117 "Accept-Encoding" .= ("gzip" :: Text),
118+ "Host" .= ("httpbin.org" :: Text),
125119 "Content-Length" .= show (T.length reflected)
126120 ],
127121 "files" .= emptyObject,
@@ -139,17 +133,18 @@ spec = do
139133 LM.partBS "bar" "bar data!"
140134 ]
141135 r <- req POST (httpbin /: "post") body jsonResponse mempty
142− let contentType = fromJust (getRequestContentType body)
136+ let Just contentType = getRequestContentType body
143137 (stripFunnyHeaders . stripOrigin) (responseBody r)
144138 `shouldBe` object
145139 [ "args" .= emptyObject,
146140 "json" .= Null,
147141 "data" .= ("" :: Text),
148− "url" .= ("http://localhost:1234/post" :: Text),
142+ "url" .= ("https://httpbin.org/post" :: Text),
149143 "headers"
150144 .= object
151145 [ "Content-Type" .= T.decodeUtf8 contentType,
152146 "Accept-Encoding" .= ("gzip" :: Text),
147+ "Host" .= ("httpbin.org" :: Text),
153148 "Content-Length" .= ("242" :: Text)
154149 ],
155150 "files" .= emptyObject,
@@ -174,10 +169,11 @@ spec = do
174169 [ "args" .= emptyObject,
175170 "json" .= Null,
176171 "data" .= contents,
177− "url" .= ("http://localhost:1234/patch" :: Text),
172+ "url" .= ("https://httpbin.org/patch" :: Text),
178173 "headers"
179174 .= object
180175 [ "Accept-Encoding" .= ("gzip" :: Text),
176+ "Host" .= ("httpbin.org" :: Text),
181177 "Content-Length" .= show (T.length contents)
182178 ],
183179 "files" .= emptyObject,
@@ -199,11 +195,12 @@ spec = do
199195 [ "args" .= emptyObject,
200196 "json" .= Null,
201197 "data" .= ("" :: Text),
202− "url" .= ("http://localhost:1234/put" :: Text),
198+ "url" .= ("https://httpbin.org/put" :: Text),
203199 "headers"
204200 .= object
205201 [ "Content-Type" .= ("application/x-www-form-urlencoded" :: Text),
206202 "Accept-Encoding" .= ("gzip" :: Text),
203+ "Host" .= ("httpbin.org" :: Text),
207204 "Content-Length" .= ("18" :: Text)
208205 ],
209206 "files" .= emptyObject,
@@ -261,17 +258,21 @@ spec = do
261258 -- TODO /response-headers
262259 -- TODO /redirect
263260
264− describe "redirects" $
265− it "follows redirects" $ do
266− r <-
267− req
268− GET
269− (httpbin /: "redirect-to")
270− NoReqBody
271− ignoreResponse
272− ("url" =: ("https://httpbin.org" :: Text))
273− responseStatusCode r `shouldBe` 200
274− responseStatusMessage r `shouldBe` "OK"
261+ -- FIXME Redirects test is temporarily disabled due to
262+ --
263+ -- https://github.com/postmanlabs/httpbin/issues/617
264+
265+ -- describe "redirects" $
266+ -- it "follows redirects" $ do
267+ -- r <-
268+ -- req
269+ -- GET
270+ -- (httpbin /: "redirect-to")
271+ -- NoReqBody
272+ -- ignoreResponse
273+ -- ("url" =: ("https://httpbin.org" :: Text))
274+ -- responseStatusCode r `shouldBe` 200
275+ -- responseStatusMessage r `shouldBe` "OK"
275276
276277 -- TODO /relative-redicet
277278 -- TODO /absolute-redirect
@@ -301,7 +302,7 @@ spec = do
301302 (httpbin /: "basic-auth" /~ user /~ password)
302303 NoReqBody
303304 ignoreResponse
304− (basicAuthUnsafe (T.encodeUtf8 user) (T.encodeUtf8 password))
305+ (basicAuth (T.encodeUtf8 user) (T.encodeUtf8 password))
305306 responseStatusCode r `shouldBe` 200
306307 responseStatusMessage r `shouldBe` "OK"
307308
@@ -401,67 +402,30 @@ blindlyThrowing = runReq defaultHttpConfig {httpConfigCheckResponse = doit}
401402 doit _ _ = error "Oops!"
402403
403404-- | 'Url' representing <https://httpbin.org>.
404−httpbin :: Url 'Http
405−httpbin = http "localhost"
406−
407−req ::
408− ( MonadHttp m,
409− HttpMethod method,
410− HttpBody body,
411− HttpResponse response,
412− HttpBodyAllowed (AllowsBody method) (ProvidesBody body)
413− ) =>
414− method ->
415− Url scheme ->
416− body ->
417− Proxy response ->
418− Option scheme ->
419− m response
420−req method url body responseProxy options =
421− Req.req method url body responseProxy (options <> defaultOptions)
422−
423−-- | Options to apply by default.
424−defaultOptions :: Option scheme
425−defaultOptions = port 1234
405+httpbin :: Url 'Https
406+httpbin = https "httpbin.org"
426407
427408-- | Remove “origin” field from JSON value. Origin may change, we don't want
428409-- to depend on that.
429410stripOrigin :: Value -> Value
430−stripOrigin (Object m) = Object (Aeson.KeyMap.delete "origin" m)
411+stripOrigin (Object m) = Object (HM.delete "origin" m)
431412stripOrigin value = value
432413
433414-- | Remove funny headers that might break the tests.
434415stripFunnyHeaders :: Value -> Value
435−stripFunnyHeaders = \case
436− Object m ->
437− Object
438− ( runIdentity
439− ( Aeson.KeyMap.alterF
440− (pure . fmap stripFunnyHeaders')
441− "headers"
442− m
443− )
444− )
445− value -> value
446−
447−-- | Similar to 'stripFunnyHeaders', but acts directly on the argument
448−-- without trying to access its "headers" field.
449−stripFunnyHeaders' :: Value -> Value
450−stripFunnyHeaders' = \case
451− Object p ->
452− Object $
453− Aeson.KeyMap.filterWithKey
454− (\k _ -> k `elem` whitelistedHeaders)
455− p
456− value -> value
457− where
458− whitelistedHeaders =
459− [ "Content-Type",
460− "Accept-Encoding",
461− "Content-Length",
462− "Foo",
463− "Baz"
464− ]
416+stripFunnyHeaders (Object m) =
417+ let f (Object p) = Object $ HM.filterWithKey (\k _ -> k `elem` hs) p
418+ f value = value
419+ hs =
420+ [ "Content-Type",
421+ "Accept-Encoding",
422+ "Host",
423+ "Content-Length",
424+ "Foo",
425+ "Baz"
426+ ]
427+ in Object (HM.adjust f "headers" m)
428+stripFunnyHeaders value = value
465429
466430-- | This is a complete test case that makes use of <https://httpbin.org> to
467431-- get various response status codes.
@@ -491,19 +455,12 @@ selector404
491455 L.responseStatus response == Y.status404 && not (B.null chunk)
492456selector404 _ = False
493457
494−-- | Same as 'selector404' except that it uses 'isStatusCodeException'.
495−selector404ByStatusCodeException :: HttpException -> Bool
496−selector404ByStatusCodeException e =
497− case isStatusCodeException e of
498− Nothing -> False
499− Just r -> responseStatusCode r == 404
500−
501458-- | The empty JSON 'Object'.
502459emptyObject :: Value
503−emptyObject = Object Aeson.KeyMap.empty
460+emptyObject = Object HM.empty
504461
505462-- | Get a rendered JSON value as 'Text'.
506−reflectJSON :: (ToJSON a) => a -> Text
463+reflectJSON :: ToJSON a => a -> Text
507464reflectJSON = T.decodeUtf8 . BL.toStrict . A.encode
508465
509466-- | Clarify to the type checker that the inner computation is in the 'IO'
pure-tests/Network/HTTP/ReqSpec.hs+21−53
@@ -13,41 +13,39 @@
1313
1414module Network.HTTP.ReqSpec (spec) where
1515
16−import Blaze.ByteString.Builder qualified as BB
16+import qualified Blaze.ByteString.Builder as BB
1717import Control.Exception (throwIO)
1818import Control.Monad
1919import Control.Retry
2020import Data.Aeson (ToJSON (..))
21−import Data.Aeson qualified as A
21+import qualified Data.Aeson as A
2222import Data.ByteString (ByteString)
23−import Data.ByteString qualified as B
24−import Data.ByteString.Char8 qualified as B8
25−import Data.ByteString.Lazy qualified as BL
26−import Data.CaseInsensitive qualified as CI
23+import qualified Data.ByteString as B
24+import qualified Data.ByteString.Char8 as B8
25+import qualified Data.ByteString.Lazy as BL
26+import qualified Data.CaseInsensitive as CI
2727import Data.Either (isRight)
28−import Data.List.NonEmpty qualified as NE
28+import qualified Data.List.NonEmpty as NE
2929import Data.Maybe (fromJust, fromMaybe, isJust, isNothing)
3030import Data.Proxy
3131import Data.Text (Text)
32−import Data.Text qualified as T
33−import Data.Text.Encoding qualified as T
32+import qualified Data.Text as T
33+import qualified Data.Text.Encoding as T
3434import Data.Time
3535import Data.Typeable (Typeable, eqT)
36−import GHC.Exts (IsList (..))
3736import GHC.Generics
38−import Language.Haskell.TH qualified as TH
39−import Language.Haskell.TH.Quote qualified as TH
40−import Network.HTTP.Client qualified as L
37+import qualified Language.Haskell.TH as TH
38+import qualified Language.Haskell.TH.Quote as TH
39+import qualified Network.HTTP.Client as L
4140import Network.HTTP.Req
42−import Network.HTTP.Types qualified as Y
43−import Network.HTTP.Types.Header qualified as Y
41+import qualified Network.HTTP.Types as Y
42+import qualified Network.HTTP.Types.Header as Y
4443import Test.Hspec
4544import Test.Hspec.Core.Spec (SpecM)
4645import Test.QuickCheck
4746import Text.URI (URI)
48−import Text.URI qualified as URI
49−import Text.URI.QQ qualified as QQ
50−import Web.FormUrlEncoded qualified as F
47+import qualified Text.URI as URI
48+import qualified Text.URI.QQ as QQ
5149
5250spec :: Spec
5351spec = do
@@ -161,13 +159,11 @@ spec = do
161159 let uriHttp = uri' {URI.uriScheme = Just [QQ.scheme|http|]}
162160 uriHttps = uri' {URI.uriScheme = Just [QQ.scheme|https|]}
163161 requestHttp <-
164− case fromJust (useURI uriHttp) of
165− Left (url', options) -> req_ GET url' NoReqBody options
166− _ -> error "(useURI uriHttp) should have returned Left"
162+ let Left (url', options) = fromJust (useURI uriHttp)
163+ in req_ GET url' NoReqBody options
167164 requestHttps <-
168− case fromJust (useURI uriHttps) of
169− Right (url', options) -> req_ GET url' NoReqBody options
170− _ -> error "(useURI uriHttps) should have returned Right"
165+ let Right (url', options) = fromJust (useURI uriHttps)
166+ in req_ GET url' NoReqBody options
171167 L.host requestHttp `shouldBe` uriHost uriHttp
172168 L.host requestHttps `shouldBe` uriHost uriHttps
173169 L.port requestHttp `shouldBe` uriPort 80 uriHttp
@@ -237,19 +233,6 @@ spec = do
237233 L.RequestBodyLBS x -> x `shouldBe` renderQuery params
238234 _ -> expectationFailure "Wrong request body constructor."
239235
240− describe "query params" $ do
241− describe "FormUrlEncodedParam" $ do
242− describe "formToQuery" $ do
243− it "should produce the same parameters as F.urlEncodeFormStable" $
244− property $ \form -> do
245− request <- req_ POST url (ReqBodyUrlEnc $ formToQuery form) mempty
246− case L.requestBody request of
247− L.RequestBodyLBS x -> x `shouldBe` F.urlEncodeFormStable form
248− _ -> expectationFailure "Wrong request body constructor"
249− specParamToList (Proxy :: Proxy FormUrlEncodedParam)
250− describe "Option" $ do
251− specParamToList (Proxy :: Proxy (Option 'Http))
252−
253236 describe "optional parameters" $ do
254237 describe "header" $ do
255238 it "sets specified header value" $
@@ -413,7 +396,7 @@ spec = do
413396 -- 'Https, Option _) type checks, so we can catch if the type of scheme
414397 -- is unspecified.
415398 let testTypeOfQuoterResult ::
416− forall a s. (Typeable a) => (a, Option s) -> Bool
399+ forall a s. Typeable a => (a, Option s) -> Bool
417400 testTypeOfQuoterResult _ = isJust $ eqT @a @(Url 'Https)
418401 in property $ testTypeOfQuoterResult [urlQ|https://example.org/|]
419402 it "doesn't work for invalid urls" $
@@ -503,9 +486,6 @@ instance Arbitrary Day where
503486instance Arbitrary DiffTime where
504487 arbitrary = secondsToDiffTime <$> arbitrary
505488
506−instance Arbitrary F.Form where
507− arbitrary = (F.Form . fromList) <$> arbitrary
508−
509489----------------------------------------------------------------------------
510490-- Helper types
511491
@@ -618,15 +598,3 @@ basicProxyAuthHeader :: ByteString -> ByteString -> ByteString
618598basicProxyAuthHeader username password =
619599 fromJust . lookup Y.hProxyAuthorization . L.requestHeaders $
620600 L.applyBasicProxyAuth username password L.defaultRequest
621−
622−-- | Spec about 'paramToList' for the type @p@.
623−specParamToList :: (QueryParam p, Monoid p) => Proxy p -> Spec
624−specParamToList typeProxy = do
625− describe "paramToList" $ do
626− it "should reproduce the parameters given by queryParam" $
627− property $ \(QueryParams params) -> do
628− let queryParam0 =
629− (mconcat $ fmap (uncurry queryParam) params)
630− `asProxyTypeOf` typeProxy
631− got = queryParamToList queryParam0
632− got `shouldBe` params
req.cabal+59−59
@@ -1,11 +1,11 @@
1−cabal-version: 2.4
1+cabal-version: 1.18
22name: req
3−version: 3.13.4
4−license: BSD-3-Clause
3+version: 3.9.0
4+license: BSD3
55license-file: LICENSE.md
66maintainer: Mark Karpov <markkarpov92@gmail.com>
77author: Mark Karpov <markkarpov92@gmail.com>
8−tested-with: ghc ==9.6.3 ghc ==9.8.2 ghc ==9.10.1
8+tested-with: ghc ==8.8.4 ghc ==8.10.4 ghc ==9.0.1
99homepage: https://github.com/mrkkrp/req
1010bug-reports: https://github.com/mrkkrp/req/issues
1111synopsis: HTTP client library
@@ -31,97 +31,97 @@ flag dev
3131
3232library
3333 exposed-modules: Network.HTTP.Req
34− default-language: GHC2021
34+ default-language: Haskell2010
3535 build-depends:
36− aeson >=0.9 && <3,
37− authenticate-oauth >=1.5 && <1.8,
38− base >=4.15 && <5,
36+ aeson >=0.9 && <1.6,
37+ authenticate-oauth >=1.5 && <1.7,
38+ base >=4.13 && <5.0,
3939 blaze-builder >=0.3 && <0.5,
40− bytestring >=0.10.8 && <0.13,
40+ bytestring >=0.10.8 && <0.12,
4141 case-insensitive >=0.2 && <1.3,
42− containers >=0.5 && <0.8,
43− crypton-connection >=0.4.2 && <0.5,
44− data-default-class >=0.2.0.0,
42+ connection >=0.2.2 && <0.4,
4543 exceptions >=0.6 && <0.11,
46− http-api-data >=0.2 && <0.7,
47− http-client >=0.7.13.1 && <0.8,
44+ http-api-data >=0.2 && <0.5,
45+ http-client >=0.7 && <0.8,
4846 http-client-tls >=0.3.2 && <0.4,
49− http-types >=0.8 && <10,
47+ http-types >=0.8 && <10.0,
5048 modern-uri >=0.3 && <0.4,
5149 monad-control >=1.0 && <1.1,
5250 mtl >=2.0 && <3.0,
53− retry >=0.8 && <0.10,
54− template-haskell >=2.19 && <2.23,
55− text >=0.2 && <2.2,
56− transformers >=0.5.3.0 && <0.7,
51+ retry >=0.8 && <0.9,
52+ template-haskell >=2.14 && <2.18,
53+ text >=0.2 && <1.3,
54+ time >=1.2 && <1.10,
55+ transformers >=0.4 && <0.6,
5756 transformers-base,
5857 unliftio-core >=0.1.1 && <0.3
5958
6059 if flag(dev)
61− ghc-options:
62− -Wall -Werror -Wpartial-fields -Wunused-packages
63− -Wno-unused-imports
60+ ghc-options: -O0 -Wall -Werror
6461
6562 else
6663 ghc-options: -O2 -Wall
6764
65+ if flag(dev)
66+ ghc-options:
67+ -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns
68+ -Wnoncanonical-monad-instances
69+
6870test-suite pure-tests
69− type: exitcode-stdio-1.0
70− main-is: Spec.hs
71− build-tool-depends: hspec-discover:hspec-discover >=2 && <3
72− hs-source-dirs: pure-tests
73− other-modules: Network.HTTP.ReqSpec
74− default-language: GHC2021
71+ type: exitcode-stdio-1.0
72+ main-is: Spec.hs
73+ build-tools: hspec-discover >=2.0 && <3.0
74+ hs-source-dirs: pure-tests
75+ other-modules: Network.HTTP.ReqSpec
76+ default-language: Haskell2010
7577 build-depends:
76− QuickCheck >=2.7 && <3,
77− aeson >=0.9 && <3,
78− base >=4.15 && <5.0,
78+ QuickCheck >=2.7 && <3.0,
79+ aeson >=0.9 && <1.6,
80+ base >=4.13 && <5.0,
7981 blaze-builder >=0.3 && <0.5,
80− bytestring >=0.10.8 && <0.13,
82+ bytestring >=0.10.8 && <0.12,
8183 case-insensitive >=0.2 && <1.3,
82− hspec >=2.0 && <3,
83− hspec-core >=2.0 && <3,
84− http-api-data >=0.2 && <0.7,
84+ hspec >=2.0 && <3.0,
85+ hspec-core >=2.0 && <3.0,
8586 http-client >=0.7 && <0.8,
86− http-types >=0.8 && <10,
87+ http-types >=0.8 && <10.0,
8788 modern-uri >=0.3 && <0.4,
89+ mtl >=2.0 && <3.0,
8890 req,
89− retry >=0.8 && <0.10,
90− template-haskell >=2.19 && <2.23,
91− text >=0.2 && <2.2,
92− time >=1.2 && <1.15
91+ retry >=0.8 && <0.9,
92+ template-haskell >=2.14 && <2.18,
93+ text >=0.2 && <1.3,
94+ time >=1.2 && <1.10
9395
9496 if flag(dev)
95− ghc-options:
96− -Wall -Werror -Wredundant-constraints -Wpartial-fields
97− -Wunused-packages
97+ ghc-options: -O0 -Wall -Werror
9898
9999 else
100100 ghc-options: -O2 -Wall
101101
102102test-suite httpbin-tests
103− type: exitcode-stdio-1.0
104− main-is: Spec.hs
105− build-tool-depends: hspec-discover:hspec-discover >=2 && <3
106− hs-source-dirs: httpbin-tests
107− other-modules: Network.HTTP.ReqSpec
108− default-language: GHC2021
103+ type: exitcode-stdio-1.0
104+ main-is: Spec.hs
105+ build-tools: hspec-discover >=2.0 && <3.0
106+ hs-source-dirs: httpbin-tests
107+ other-modules: Network.HTTP.ReqSpec
108+ default-language: Haskell2010
109109 build-depends:
110− QuickCheck >=2.7 && <3,
111− aeson >=2 && <3,
112− base >=4.15 && <5,
113− bytestring >=0.10.8 && <0.13,
110+ QuickCheck >=2.7 && <3.0,
111+ aeson >=0.9 && <1.6,
112+ base >=4.13 && <5.0,
113+ bytestring >=0.10.8 && <0.12,
114114 hspec >=2.0 && <3.0,
115115 http-client >=0.7 && <0.8,
116− http-types >=0.8 && <10,
116+ http-types >=0.8 && <10.0,
117117 monad-control >=1.0 && <1.1,
118+ mtl >=2.0 && <3.0,
118119 req,
119− text >=0.2 && <2.2
120+ text >=0.2 && <1.3,
121+ unordered-containers >=0.2.5 && <0.3
120122
121123 if flag(dev)
122− ghc-options:
123− -Wall -Werror -Wredundant-constraints -Wpartial-fields
124− -Wunused-packages
124+ ghc-options: -O0 -Wall -Werror
125125
126126 else
127− buildable: False
127+ ghc-options: -O2 -Wall