From 70f1ad896dc3f6a61b9fb8947cfaae6d9c83cd82 Mon Sep 17 00:00:00 2001 From: Nitin Prakash Date: Wed, 2 Oct 2024 16:53:20 +0530 Subject: [PATCH 1/6] Bump dependencies to support newer GHCs --- cabal.project | 7 ++- hreq-client/hreq-client.cabal | 52 +++++++++---------- hreq-conduit/hreq-conduit.cabal | 36 ++++++------- hreq-core/hreq-core.cabal | 29 ++++++----- hreq-core/src/Data/Singletons.hs | 4 +- hreq-core/src/Hreq/Core/Client/HasRequest.hs | 2 +- hreq-core/src/Hreq/Core/Client/HasResponse.hs | 35 +++++++------ hreq-core/src/Hreq/Core/Client/Internal.hs | 1 + 8 files changed, 84 insertions(+), 82 deletions(-) diff --git a/cabal.project b/cabal.project index 5174797..b5444dd 100644 --- a/cabal.project +++ b/cabal.project @@ -1,5 +1,4 @@ packages: - ./ - hreq-client/ - hreq-core/ - hreq-conduit/ + ./hreq-client/ + ./hreq-core/ + ./hreq-conduit/ diff --git a/hreq-client/hreq-client.cabal b/hreq-client/hreq-client.cabal index a3eb0f5..d5c5cfc 100644 --- a/hreq-client/hreq-client.cabal +++ b/hreq-client/hreq-client.cabal @@ -38,23 +38,23 @@ library default-extensions: LambdaCase DeriveGeneric FlexibleInstances FlexibleContexts ScopedTypeVariables TypeApplications TypeOperators MultiParamTypeClasses RecordWildCards TypeApplications TypeFamilies OverloadedStrings GADTs GeneralizedNewtypeDeriving FunctionalDependencies ConstraintKinds RankNTypes PolyKinds DataKinds KindSignatures ViewPatterns UndecidableInstances StrictData build-depends: - base >= 4.10.1 && < 5, - base-compat >= 0.10.5 && < 0.13, - bytestring >= 0.10.8 && < 0.11, - containers >= 0.5.7.1 && < 0.7, - exceptions >= 0.10.0 && < 0.11, - http-client >= 0.6.4 && < 0.7, - http-client-tls >= 0.3.5 && < 0.4, - hreq-core >= 0.1.1, - http-media >= 0.8.0 && < 0.9, - http-types >= 0.12.3 && < 0.13, - mtl >= 2.2.2 && < 3.0, - retry >= 0.8 && < 0.9, - time >= 1.6.0.1 && < 2.0, - text >= 1.2.4 && < 1.3, - stm >= 2.4.5.1 && < 2.6, - unliftio-core >= 0.1.2 && < 0.2.0, - string-conversions >= 0.4.0 && < 0.5 + base >= 4.14 && < 5, + base-compat >= 0.10.5 && < 0.15, + bytestring >= 0.10.8 && < 0.13, + containers >= 0.5.7.1 && < 0.8, + exceptions >= 0.10.0 && < 0.11, + http-client >= 0.6.4 && < 0.8, + http-client-tls >= 0.3.5 && < 0.4, + hreq-core >= 0.1.1, + http-media >= 0.8.0 && < 0.9, + http-types >= 0.12.3 && < 0.13, + mtl >= 2.2.2 && < 3.0, + retry >= 0.8 && < 0.9, + time >= 1.6.0.1 && < 2.0, + text >= 1.2.4 && < 2.2, + stm >= 2.4.5.1 && < 2.6, + unliftio-core ^>= 0.2, + string-conversions >= 0.4.0 && < 0.5 ghc-options: -Wall @@ -78,16 +78,16 @@ executable example build-depends: base >= 4.10.1 && < 5 , hreq-client - , aeson >= 1.4.5 && < 1.5 - , text >= 1.2.4 && < 1.3 + , aeson >= 1.4.5 && < 1.6 || >= 2.2 && < 2.3 + , text >= 1.2.4 && < 1.3 || >= 2.0 && < 2.2 test-suite spec build-depends: - base >= 4.10.1 && < 5 - , aeson >= 1.4.5 && < 1.5 - , containers >= 0.5.7.1 && < 0.7 - , http-types >= 0.12.3 && < 0.13 - , hspec >= 2.6.0 && < 2.8 + base >= 4.10.1 && < 5 + , aeson >= 1.4.5 && < 1.6 || >= 2.2 && < 2.3 + , containers >= 0.5.7.1 && < 0.8 + , http-types >= 0.12.3 && < 0.13 + , hspec >= 2.6.0 && < 2.8 , hreq-client , hreq-core main-is: Spec.hs @@ -110,8 +110,8 @@ test-suite doctests main-is: DocTests.hs build-depends: base >= 4.10.1 && < 5 - , aeson >= 1.4.5 && < 1.5 - , doctest >=0.15 && < 0.17 + , aeson >= 1.4.5 && < 1.6 || >=2.2 && <2.3 + , doctest >= 0.15 && < 0.17 , hreq-client ghc-options: -Wall -threaded diff --git a/hreq-conduit/hreq-conduit.cabal b/hreq-conduit/hreq-conduit.cabal index f3fff98..8c65f51 100644 --- a/hreq-conduit/hreq-conduit.cabal +++ b/hreq-conduit/hreq-conduit.cabal @@ -39,17 +39,17 @@ library default-extensions: LambdaCase DeriveGeneric FlexibleInstances FlexibleContexts ScopedTypeVariables TypeApplications TypeOperators MultiParamTypeClasses RecordWildCards TypeApplications TypeFamilies OverloadedStrings GADTs GeneralizedNewtypeDeriving FunctionalDependencies ConstraintKinds RankNTypes PolyKinds DataKinds KindSignatures ViewPatterns UndecidableInstances StrictData build-depends: - base >= 4.10.1 && < 5, - bytestring >= 0.10.8 && < 0.11, - exceptions >= 0.10.0 && < 0.11, - http-client >= 0.6.4 && < 0.7, - http-types >= 0.12.3 && < 0.13, - hreq-client >= 0.1.0, - hreq-core >= 0.1.0, - conduit >=1.3.1 && <1.4, - mtl >= 2.2.2 && < 3.0, - retry >= 0.8 && < 0.9, - unliftio-core >= 0.1.2 && < 0.2.0 + base >= 4.14 && < 5, + bytestring >= 0.10.8 && < 0.13, + exceptions >= 0.10.0 && < 0.11, + http-client >= 0.6.4 && < 0.7, + http-types >= 0.12.3 && < 0.13, + hreq-client >= 0.1.0, + hreq-core >= 0.1.0, + conduit >= 1.3.1 && < 1.4, + mtl >= 2.2.2 && < 3.0, + retry >= 0.8 && < 0.9, + unliftio-core ^>= 0.2.0 ghc-options: -Wall @@ -69,12 +69,12 @@ test-suite spec build-depends: base >= 4.10.1 && < 5 - , conduit >=1.3.1 && <1.4 + , conduit >= 1.3.1 && <1.4 , http-types >= 0.12.3 && < 0.13 , hspec >= 2.6.0 && < 2.8 , hreq-conduit , string-conversions >= 0.4.0 && < 0.5 - , text >= 1.2.4 && < 1.3 + , text >= 1.2.4 && < 1.3 || >= 2.0 && < 2.2 main-is: Spec.hs other-modules: Hreq.HttpBin.SuccessSpec hs-source-dirs: test @@ -87,9 +87,9 @@ test-suite spec test-suite readme build-depends: - base >= 4.10.1 && < 5 - , conduit >=1.3.1 && <1.4 - , bytestring >= 0.10.8 && < 0.11 + base >= 4.10.1 && < 5 + , conduit >= 1.3.1 && < 1.4 + , bytestring >= 0.10.8 && < 0.11 , hreq-conduit , string-conversions >= 0.4.0 && < 0.5 , text >= 1.2.4 && < 1.3 @@ -105,8 +105,8 @@ test-suite doctests main-is: DocTests.hs build-depends: base >= 4.10.1 && < 5 - , aeson >= 1.4.5 && < 1.5 - , doctest >=0.15 && < 0.17 + , aeson >= 1.4.5 && < 1.6 || >= 2.2 && < 2.3 + , doctest >= 0.15 && < 0.17 , hreq-conduit ghc-options: -Wall -threaded diff --git a/hreq-core/hreq-core.cabal b/hreq-core/hreq-core.cabal index bf5e968..0ca36e5 100644 --- a/hreq-core/hreq-core.cabal +++ b/hreq-core/hreq-core.cabal @@ -54,19 +54,20 @@ library default-extensions: LambdaCase DeriveGeneric FlexibleInstances FlexibleContexts ScopedTypeVariables TypeApplications TypeOperators MultiParamTypeClasses RecordWildCards TypeApplications TypeFamilies OverloadedStrings GADTs GeneralizedNewtypeDeriving FunctionalDependencies ConstraintKinds RankNTypes PolyKinds DataKinds KindSignatures ViewPatterns UndecidableInstances StrictData build-depends: - base >= 4.10.1 && < 5, - base-compat >= 0.10.5 && < 0.13, - aeson >= 1.4.5 && < 1.5, - attoparsec >= 0.13.2.2 && < 0.14, - bytestring >= 0.10.8 && < 0.11, - containers >= 0.5.7.1 && < 0.7, - exceptions >= 0.10.0 && < 0.11, - http-api-data >= 0.4.1 && < 0.5, - http-media >= 0.8.0 && < 0.9, - http-types >= 0.12.3 && < 0.13, - mtl >= 2.2.2 && < 3.0, - text >= 1.2.4 && < 1.3, - string-conversions >= 0.4.0 && < 0.5 + base >= 4.14 && < 5, + base-compat >= 0.10.5 && < 0.13, + aeson >= 1.4.5 && < 1.6 || >= 2.2 && < 2.3, + attoparsec >= 0.13.2.2 && < 0.15, + attoparsec-aeson >= 2.0, + bytestring >= 0.10.8 && < 0.13, + containers >= 0.5.7.1 && < 0.8, + exceptions >= 0.10.0 && < 0.11, + http-api-data >= 0.4.1 && < 0.7, + http-media >= 0.8.0 && < 0.9, + http-types >= 0.12.3 && < 0.13, + mtl >= 2.2.2 && < 3.0, + text >= 1.2.4 && < 2.2, + string-conversions >= 0.4.0 && < 0.5 ghc-options: -Wall -Wincomplete-uni-patterns @@ -86,7 +87,7 @@ test-suite doctests main-is: DocTests.hs build-depends: base >= 4.10.1 && < 5 - , doctest >=0.15 && < 0.17 + , doctest >= 0.15 && < 0.17 , hreq-core ghc-options: -Wall -threaded diff --git a/hreq-core/src/Data/Singletons.hs b/hreq-core/src/Data/Singletons.hs index 7b086df..666e582 100644 --- a/hreq-core/src/Data/Singletons.hs +++ b/hreq-core/src/Data/Singletons.hs @@ -15,11 +15,11 @@ ===Attribution Some of the code in this module was directly borrowed from the Singletons library -} -{-# LANGUAGE TypeInType #-} +{-# LANGUAGE DataKinds #-} module Data.Singletons where import Data.Kind -import GHC.TypeLits +import GHC.TypeLits hiding (SSymbol, SNat) import Data.Typeable -- * Sing Type family diff --git a/hreq-core/src/Hreq/Core/Client/HasRequest.hs b/hreq-core/src/Hreq/Core/Client/HasRequest.hs index b07ae41..37a726c 100644 --- a/hreq-core/src/Hreq/Core/Client/HasRequest.hs +++ b/hreq-core/src/Hreq/Core/Client/HasRequest.hs @@ -11,7 +11,7 @@ import Data.Kind import Data.Hlist import Data.Proxy import Data.Singletons -import GHC.TypeLits +import GHC.TypeLits hiding (withKnownNat, withKnownSymbol) import Data.String (fromString) import Data.String.Conversions (cs) import Data.List (intersperse) diff --git a/hreq-core/src/Hreq/Core/Client/HasResponse.hs b/hreq-core/src/Hreq/Core/Client/HasResponse.hs index 3818873..8f3de75 100644 --- a/hreq-core/src/Hreq/Core/Client/HasResponse.hs +++ b/hreq-core/src/Hreq/Core/Client/HasResponse.hs @@ -11,7 +11,7 @@ import Data.Hlist import Data.Proxy import Data.Singletons import qualified Data.List.NonEmpty as NE -import GHC.TypeLits +import GHC.TypeLits hiding (withKnownNat) import Network.HTTP.Types (hContentType) import Hreq.Core.API @@ -71,9 +71,9 @@ instance {-# OVERLAPPING #-} httpRes _ res = do let expectedCode = fromIntegral @Integer @Int $ natVal (Proxy @n) rcode = resStatusCode res - when (expectedCode /= rcode) $ throwError (InvalidStatusCode res) - - return res + if expectedCode /= rcode + then throwError (InvalidStatusCode res) + else do return res -- | Expected status code much match received code in a response code list instance {-# OVERLAPPING #-} @@ -88,10 +88,11 @@ instance {-# OVERLAPPING #-} httpRes _ response = do let expectedCode = fromIntegral @Integer @Int $ natVal (Proxy @n) rcode = resStatusCode response - when (expectedCode /= rcode) $ throwError (InvalidStatusCode response) - - case sing @('Res (r ': rs)) of - SRes xs -> decodeAsHlist xs response + if expectedCode /= rcode + then throwError (InvalidStatusCode response) + else do + case sing @('Res (r ': rs)) of + SRes xs -> decodeAsHlist xs response instance {-# OVERLAPPING #-} ( MediaDecode ctyp a @@ -137,12 +138,12 @@ decodeAsBody decodeAsBody _ response = do responseContentType <- checkContentType - unless (any (responseContentType `matches`) accepts) - . throwError $ UnsupportedContentType (NE.head accepts) response - - case mediaDecode ctypProxy (resBody response) of - Left err -> throwError $ DecodeFailure (unDecodeError err) response - Right val -> pure val + if any (responseContentType `matches`) accepts + then throwError $ UnsupportedContentType (NE.head accepts) response + else do + case mediaDecode ctypProxy (resBody response) of + Left err -> throwError $ DecodeFailure (unDecodeError err) response + Right val -> pure val where ctypProxy :: Proxy ctyp ctypProxy = Proxy @@ -182,10 +183,10 @@ decodeAsHlist srs response = case srs of let rcode = resStatusCode response expectedCode = withKnownNat snat (fromIntegral @Integer @Int $ natVal snat) - when (rcode /= expectedCode) $ throwError (InvalidStatusCode response) + if rcode /= expectedCode + then throwError (InvalidStatusCode response) + else do decodeAsHlist xs response - decodeAsHlist xs response - -- Should never match because we have a class instance -- that triggers a type error when 'Raw' is in a non-singleton -- type level list diff --git a/hreq-core/src/Hreq/Core/Client/Internal.hs b/hreq-core/src/Hreq/Core/Client/Internal.hs index 6901f3a..ab5add1 100644 --- a/hreq-core/src/Hreq/Core/Client/Internal.hs +++ b/hreq-core/src/Hreq/Core/Client/Internal.hs @@ -5,6 +5,7 @@ module Hreq.Core.Client.Internal where import Control.Monad.Except +import Control.Monad.IO.Class (MonadIO (..)) import Data.Proxy import Hreq.Core.API From 361fc2770a0d9668e707a9cc8ccb997b63e58f2e Mon Sep 17 00:00:00 2001 From: Nitin Prakash Date: Wed, 2 Oct 2024 17:46:49 +0530 Subject: [PATCH 2/6] import fixes --- hreq-client/hreq-client.cabal | 6 +++--- hreq-conduit/hreq-conduit.cabal | 6 +++--- hreq-conduit/src/Hreq/Conduit/Internal/HTTP.hs | 8 ++++---- hreq-core/hreq-core.cabal | 4 ++-- hreq-core/src/Data/Singletons.hs | 6 ++++++ hreq-core/src/Hreq/Core/Client/HasRequest.hs | 7 ++++++- hreq-core/src/Hreq/Core/Client/HasResponse.hs | 5 +++++ hreq-core/src/Hreq/Core/Client/Internal.hs | 2 +- 8 files changed, 30 insertions(+), 14 deletions(-) diff --git a/hreq-client/hreq-client.cabal b/hreq-client/hreq-client.cabal index d5c5cfc..f511552 100644 --- a/hreq-client/hreq-client.cabal +++ b/hreq-client/hreq-client.cabal @@ -109,9 +109,9 @@ test-suite doctests type: exitcode-stdio-1.0 main-is: DocTests.hs build-depends: - base >= 4.10.1 && < 5 - , aeson >= 1.4.5 && < 1.6 || >=2.2 && <2.3 - , doctest >= 0.15 && < 0.17 + base >= 4.14 && < 5 + , aeson >= 1.4.5 && < 1.6 || >= 2.2 && < 2.3 + , doctest >= 0.15 && < 0.17 , hreq-client ghc-options: -Wall -threaded diff --git a/hreq-conduit/hreq-conduit.cabal b/hreq-conduit/hreq-conduit.cabal index 8c65f51..e58da76 100644 --- a/hreq-conduit/hreq-conduit.cabal +++ b/hreq-conduit/hreq-conduit.cabal @@ -104,9 +104,9 @@ test-suite doctests type: exitcode-stdio-1.0 main-is: DocTests.hs build-depends: - base >= 4.10.1 && < 5 - , aeson >= 1.4.5 && < 1.6 || >= 2.2 && < 2.3 - , doctest >= 0.15 && < 0.17 + base >= 4.14 && < 5 + , aeson >= 1.4.5 && < 1.6 || >= 2.2 && < 2.3 + , doctest >= 0.15 && < 0.17 , hreq-conduit ghc-options: -Wall -threaded diff --git a/hreq-conduit/src/Hreq/Conduit/Internal/HTTP.hs b/hreq-conduit/src/Hreq/Conduit/Internal/HTTP.hs index ff74e4c..17e906e 100644 --- a/hreq-conduit/src/Hreq/Conduit/Internal/HTTP.hs +++ b/hreq-conduit/src/Hreq/Conduit/Internal/HTTP.hs @@ -75,12 +75,12 @@ runStreamingHttp runStreamingHttp req f = do config <- ask let manager = httpManager config - let baseUrl = httpBaseUrl config - let statusRange = httpStatuses config + baseUrl = httpBaseUrl config + statusRange = httpStatuses config - let httpRequest = requestToHTTPRequest baseUrl req + httpRequest = requestToHTTPRequest baseUrl req - let action = liftIO $ catchConnectionError $ HTTP.withResponse httpRequest manager $ \res -> do + action = liftIO $ catchConnectionError $ HTTP.withResponse httpRequest manager $ \res -> do checkStreamResponse res statusRange f (ResBodyStream $ bodyReaderSource (HTTP.responseBody res)) diff --git a/hreq-core/hreq-core.cabal b/hreq-core/hreq-core.cabal index 0ca36e5..bf130fa 100644 --- a/hreq-core/hreq-core.cabal +++ b/hreq-core/hreq-core.cabal @@ -86,8 +86,8 @@ test-suite doctests type: exitcode-stdio-1.0 main-is: DocTests.hs build-depends: - base >= 4.10.1 && < 5 - , doctest >= 0.15 && < 0.17 + base >= 4.14 && < 5 + , doctest >= 0.15 && < 0.17 , hreq-core ghc-options: -Wall -threaded diff --git a/hreq-core/src/Data/Singletons.hs b/hreq-core/src/Data/Singletons.hs index 666e582..5dac4ef 100644 --- a/hreq-core/src/Data/Singletons.hs +++ b/hreq-core/src/Data/Singletons.hs @@ -15,11 +15,17 @@ ===Attribution Some of the code in this module was directly borrowed from the Singletons library -} +{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} module Data.Singletons where import Data.Kind + +#if MIN_VERSION_base(4,18,0) import GHC.TypeLits hiding (SSymbol, SNat) +#else +import GHC.TypeLits +#endif import Data.Typeable -- * Sing Type family diff --git a/hreq-core/src/Hreq/Core/Client/HasRequest.hs b/hreq-core/src/Hreq/Core/Client/HasRequest.hs index 37a726c..d3a5b28 100644 --- a/hreq-core/src/Hreq/Core/Client/HasRequest.hs +++ b/hreq-core/src/Hreq/Core/Client/HasRequest.hs @@ -1,7 +1,8 @@ -- | This module provides a 'HasRequest' class that Interprets -- a 'ReqContent' type level list into 'Request' data -- -{-# LANGUAGE PatternSynonyms #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE PatternSynonyms #-} module Hreq.Core.Client.HasRequest where import Prelude () @@ -11,7 +12,11 @@ import Data.Kind import Data.Hlist import Data.Proxy import Data.Singletons +#if MIN_VERSION_base(4,18,0) import GHC.TypeLits hiding (withKnownNat, withKnownSymbol) +#else +import GHC.TypeLits +#endif import Data.String (fromString) import Data.String.Conversions (cs) import Data.List (intersperse) diff --git a/hreq-core/src/Hreq/Core/Client/HasResponse.hs b/hreq-core/src/Hreq/Core/Client/HasResponse.hs index 8f3de75..55905ac 100644 --- a/hreq-core/src/Hreq/Core/Client/HasResponse.hs +++ b/hreq-core/src/Hreq/Core/Client/HasResponse.hs @@ -3,6 +3,7 @@ -- -- For instance @Verb GET '[]@ gets interpreted as an empty response of type Unit i.e @()@ -- +{-# LANGUAGE CPP #-} module Hreq.Core.Client.HasResponse where import Control.Monad.Except @@ -11,7 +12,11 @@ import Data.Hlist import Data.Proxy import Data.Singletons import qualified Data.List.NonEmpty as NE +#if MIN_VERSION_base(4,18,0) import GHC.TypeLits hiding (withKnownNat) +#else +import GHC.TypeLits +#endif import Network.HTTP.Types (hContentType) import Hreq.Core.API diff --git a/hreq-core/src/Hreq/Core/Client/Internal.hs b/hreq-core/src/Hreq/Core/Client/Internal.hs index ab5add1..2e48a9b 100644 --- a/hreq-core/src/Hreq/Core/Client/Internal.hs +++ b/hreq-core/src/Hreq/Core/Client/Internal.hs @@ -5,7 +5,7 @@ module Hreq.Core.Client.Internal where import Control.Monad.Except -import Control.Monad.IO.Class (MonadIO (..)) +import Control.Monad.IO.Class (liftIO) import Data.Proxy import Hreq.Core.API From 2471f8a0e4ff2558ebb06c442d02b7f8b6ba307d Mon Sep 17 00:00:00 2001 From: Nitin Prakash Date: Thu, 3 Oct 2024 00:32:18 +0530 Subject: [PATCH 3/6] bump doctest --- hreq-client/hreq-client.cabal | 2 +- hreq-conduit/hreq-conduit.cabal | 2 +- hreq-core/hreq-core.cabal | 2 +- hreq-core/src/Data/Singletons.hs | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/hreq-client/hreq-client.cabal b/hreq-client/hreq-client.cabal index f511552..f5cc014 100644 --- a/hreq-client/hreq-client.cabal +++ b/hreq-client/hreq-client.cabal @@ -111,7 +111,7 @@ test-suite doctests build-depends: base >= 4.14 && < 5 , aeson >= 1.4.5 && < 1.6 || >= 2.2 && < 2.3 - , doctest >= 0.15 && < 0.17 + , doctest >= 0.15 && < 0.23 , hreq-client ghc-options: -Wall -threaded diff --git a/hreq-conduit/hreq-conduit.cabal b/hreq-conduit/hreq-conduit.cabal index e58da76..937249c 100644 --- a/hreq-conduit/hreq-conduit.cabal +++ b/hreq-conduit/hreq-conduit.cabal @@ -106,7 +106,7 @@ test-suite doctests build-depends: base >= 4.14 && < 5 , aeson >= 1.4.5 && < 1.6 || >= 2.2 && < 2.3 - , doctest >= 0.15 && < 0.17 + , doctest >= 0.15 && < 0.23 , hreq-conduit ghc-options: -Wall -threaded diff --git a/hreq-core/hreq-core.cabal b/hreq-core/hreq-core.cabal index bf130fa..dec4133 100644 --- a/hreq-core/hreq-core.cabal +++ b/hreq-core/hreq-core.cabal @@ -87,7 +87,7 @@ test-suite doctests main-is: DocTests.hs build-depends: base >= 4.14 && < 5 - , doctest >= 0.15 && < 0.17 + , doctest >= 0.15 && < 0.23 , hreq-core ghc-options: -Wall -threaded diff --git a/hreq-core/src/Data/Singletons.hs b/hreq-core/src/Data/Singletons.hs index 5dac4ef..65093c3 100644 --- a/hreq-core/src/Data/Singletons.hs +++ b/hreq-core/src/Data/Singletons.hs @@ -17,6 +17,7 @@ -} {-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} +{-# LANGUAGE PolyKinds #-} module Data.Singletons where import Data.Kind From 37e8e0b07d76de98b4abc989df75faa164d862bf Mon Sep 17 00:00:00 2001 From: Nitin Prakash Date: Tue, 15 Oct 2024 17:22:05 +0530 Subject: [PATCH 4/6] Bump http-client --- .travis.yml | 8 ++++---- hreq-client/hreq-client.cabal | 8 ++++---- hreq-conduit/hreq-conduit.cabal | 10 +++++----- hreq-core/hreq-core.cabal | 8 ++++---- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 76c22bd..f7149aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,10 +12,10 @@ cache: matrix: include: - - ghc: 8.8.1 - - ghc: 8.6.5 - - ghc: 8.4.4 - - ghc: 8.2.2 + - ghc: 9.8.2 + - ghc: 9.6.6 + - ghc: 9.4.8 + - ghc: 9.2.8 install: - | diff --git a/hreq-client/hreq-client.cabal b/hreq-client/hreq-client.cabal index f5cc014..993eb83 100644 --- a/hreq-client/hreq-client.cabal +++ b/hreq-client/hreq-client.cabal @@ -13,10 +13,10 @@ license: MIT license-file: LICENSE.md extra-doc-files: CHANGELOG.md, README.md tested-with: - GHC ==8.2.2 - || ==8.4.4 - || ==8.6.5 - || ==8.8.1 + GHC ==9.2.8 + || ==9.4.8 + || ==9.6.6 + || ==9.8.2 build-type: Custom source-repository head diff --git a/hreq-conduit/hreq-conduit.cabal b/hreq-conduit/hreq-conduit.cabal index 937249c..10fc5e2 100644 --- a/hreq-conduit/hreq-conduit.cabal +++ b/hreq-conduit/hreq-conduit.cabal @@ -13,10 +13,10 @@ license: MIT license-file: LICENSE.md extra-doc-files: CHANGELOG.md, README.md tested-with: - GHC ==8.2.2 - || ==8.4.4 - || ==8.6.5 - || ==8.8.1 + GHC ==9.2.8 + || ==9.4.8 + || ==9.6.6 + || ==9.8.2 build-type: Custom custom-setup @@ -42,7 +42,7 @@ library base >= 4.14 && < 5, bytestring >= 0.10.8 && < 0.13, exceptions >= 0.10.0 && < 0.11, - http-client >= 0.6.4 && < 0.7, + http-client >= 0.6.4 && < 0.8, http-types >= 0.12.3 && < 0.13, hreq-client >= 0.1.0, hreq-core >= 0.1.0, diff --git a/hreq-core/hreq-core.cabal b/hreq-core/hreq-core.cabal index dec4133..e81e7bb 100644 --- a/hreq-core/hreq-core.cabal +++ b/hreq-core/hreq-core.cabal @@ -13,10 +13,10 @@ license: MIT license-file: LICENSE.md extra-doc-files: CHANGELOG.md, README.md tested-with: - GHC ==8.2.2 - || ==8.4.4 - || ==8.6.5 - || ==8.8.1 + GHC ==9.2.8 + || ==9.4.8 + || ==9.6.6 + || ==9.8.2 build-type: Custom source-repository head From 83bcfb5c384a73bf35d0b62428ca31c16bc15788 Mon Sep 17 00:00:00 2001 From: Nitin Prakash Date: Tue, 15 Oct 2024 19:00:34 +0530 Subject: [PATCH 5/6] revert changes --- hreq-core/src/Hreq/Core/Client/HasResponse.hs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/hreq-core/src/Hreq/Core/Client/HasResponse.hs b/hreq-core/src/Hreq/Core/Client/HasResponse.hs index 55905ac..2a1d5d1 100644 --- a/hreq-core/src/Hreq/Core/Client/HasResponse.hs +++ b/hreq-core/src/Hreq/Core/Client/HasResponse.hs @@ -6,6 +6,7 @@ {-# LANGUAGE CPP #-} module Hreq.Core.Client.HasResponse where +import Control.Monad (when, unless) import Control.Monad.Except import Data.Kind import Data.Hlist @@ -76,9 +77,9 @@ instance {-# OVERLAPPING #-} httpRes _ res = do let expectedCode = fromIntegral @Integer @Int $ natVal (Proxy @n) rcode = resStatusCode res - if expectedCode /= rcode - then throwError (InvalidStatusCode res) - else do return res + when (expectedCode /= rcode) $ throwError (InvalidStatusCode res) + + return res -- | Expected status code much match received code in a response code list instance {-# OVERLAPPING #-} @@ -93,11 +94,10 @@ instance {-# OVERLAPPING #-} httpRes _ response = do let expectedCode = fromIntegral @Integer @Int $ natVal (Proxy @n) rcode = resStatusCode response - if expectedCode /= rcode - then throwError (InvalidStatusCode response) - else do - case sing @('Res (r ': rs)) of - SRes xs -> decodeAsHlist xs response + when (expectedCode /= rcode) $ throwError (InvalidStatusCode response) + + case sing @('Res (r ': rs)) of + SRes xs -> decodeAsHlist xs response instance {-# OVERLAPPING #-} ( MediaDecode ctyp a @@ -143,12 +143,12 @@ decodeAsBody decodeAsBody _ response = do responseContentType <- checkContentType - if any (responseContentType `matches`) accepts - then throwError $ UnsupportedContentType (NE.head accepts) response - else do - case mediaDecode ctypProxy (resBody response) of - Left err -> throwError $ DecodeFailure (unDecodeError err) response - Right val -> pure val + unless (any (responseContentType `matches`) accepts) + . throwError $ UnsupportedContentType (NE.head accepts) response + + case mediaDecode ctypProxy (resBody response) of + Left err -> throwError $ DecodeFailure (unDecodeError err) response + Right val -> pure val where ctypProxy :: Proxy ctyp ctypProxy = Proxy @@ -188,9 +188,9 @@ decodeAsHlist srs response = case srs of let rcode = resStatusCode response expectedCode = withKnownNat snat (fromIntegral @Integer @Int $ natVal snat) - if rcode /= expectedCode - then throwError (InvalidStatusCode response) - else do decodeAsHlist xs response + when (rcode /= expectedCode) $ throwError (InvalidStatusCode response) + + decodeAsHlist xs response -- Should never match because we have a class instance -- that triggers a type error when 'Raw' is in a non-singleton From c71e92e401f50dccbb763504323271faf09cdada Mon Sep 17 00:00:00 2001 From: Nitin Prakash Date: Tue, 15 Oct 2024 21:22:44 +0530 Subject: [PATCH 6/6] run stylish haskell --- hreq-core/src/Data/Singletons.hs | 4 ++-- hreq-core/src/Hreq/Core/API/Request.hs | 2 +- hreq-core/src/Hreq/Core/API/TypeLevel.hs | 12 ++++++------ hreq-core/src/Hreq/Core/Client/HasRequest.hs | 6 +++--- hreq-core/src/Hreq/Core/Client/HasResponse.hs | 8 ++++---- hreq-core/src/Hreq/Core/Client/RunClient.hs | 6 +++--- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/hreq-core/src/Data/Singletons.hs b/hreq-core/src/Data/Singletons.hs index 65093c3..e8d4c47 100644 --- a/hreq-core/src/Data/Singletons.hs +++ b/hreq-core/src/Data/Singletons.hs @@ -15,7 +15,7 @@ ===Attribution Some of the code in this module was directly borrowed from the Singletons library -} -{-# LANGUAGE CPP #-} +{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE PolyKinds #-} module Data.Singletons where @@ -23,7 +23,7 @@ module Data.Singletons where import Data.Kind #if MIN_VERSION_base(4,18,0) -import GHC.TypeLits hiding (SSymbol, SNat) +import GHC.TypeLits hiding (SNat, SSymbol) #else import GHC.TypeLits #endif diff --git a/hreq-core/src/Hreq/Core/API/Request.hs b/hreq-core/src/Hreq/Core/API/Request.hs index f8a3b4c..e18803b 100644 --- a/hreq-core/src/Hreq/Core/API/Request.hs +++ b/hreq-core/src/Hreq/Core/API/Request.hs @@ -4,7 +4,7 @@ module Hreq.Core.API.Request where import Data.Kind (Type) -import Data.Singletons (Sing, SingI(..)) +import Data.Singletons (Sing, SingI (..)) import GHC.TypeLits (Symbol) -- * Request Type diff --git a/hreq-core/src/Hreq/Core/API/TypeLevel.hs b/hreq-core/src/Hreq/Core/API/TypeLevel.hs index c3e47b6..5fd124c 100644 --- a/hreq-core/src/Hreq/Core/API/TypeLevel.hs +++ b/hreq-core/src/Hreq/Core/API/TypeLevel.hs @@ -2,18 +2,18 @@ -- module Hreq.Core.API.TypeLevel where -import Data.Kind (Type, Constraint) -import GHC.TypeLits (Symbol, TypeError, ErrorMessage(..), KnownSymbol, KnownNat) +import Data.Kind (Constraint, Type) +import GHC.TypeLits (ErrorMessage (..), KnownNat, KnownSymbol, Symbol, TypeError) import Network.HTTP.Types (Header) import Web.HttpApiData (ToHttpApiData) -import Hreq.Core.Client.BasicAuth (BasicAuthData) -import Hreq.Core.API.Request (ReqContent(..)) -import Hreq.Core.API.Response (ResContent (..)) import Hreq.Core.API.Internal ((:>)) -import Hreq.Core.API.MediaType (MediaDecode, MediaEncode, HasMediaType) +import Hreq.Core.API.MediaType (HasMediaType, MediaDecode, MediaEncode) +import Hreq.Core.API.Request (ReqContent (..)) +import Hreq.Core.API.Response (ResContent (..)) import Hreq.Core.API.Streaming (HasStreamBody) import Hreq.Core.API.Verb (Verb) +import Hreq.Core.Client.BasicAuth (BasicAuthData) -- | 'ApiToReq' transforms an API type into a type level list of -- Request component content types. diff --git a/hreq-core/src/Hreq/Core/Client/HasRequest.hs b/hreq-core/src/Hreq/Core/Client/HasRequest.hs index d3a5b28..982ff8d 100644 --- a/hreq-core/src/Hreq/Core/Client/HasRequest.hs +++ b/hreq-core/src/Hreq/Core/Client/HasRequest.hs @@ -8,8 +8,8 @@ module Hreq.Core.Client.HasRequest where import Prelude () import Prelude.Compat -import Data.Kind import Data.Hlist +import Data.Kind import Data.Proxy import Data.Singletons #if MIN_VERSION_base(4,18,0) @@ -17,14 +17,14 @@ import GHC.TypeLits hiding (withKnownNat, withKnownSymbol) #else import GHC.TypeLits #endif +import Data.List (intersperse) import Data.String (fromString) import Data.String.Conversions (cs) -import Data.List (intersperse) import qualified Data.Text as T (concat) import Hreq.Core.API -import Hreq.Core.Client.Request import Hreq.Core.Client.BasicAuth +import Hreq.Core.Client.Request import Network.HTTP.Types (QueryItem) pattern Empty :: Hlist '[] diff --git a/hreq-core/src/Hreq/Core/Client/HasResponse.hs b/hreq-core/src/Hreq/Core/Client/HasResponse.hs index 2a1d5d1..86eb192 100644 --- a/hreq-core/src/Hreq/Core/Client/HasResponse.hs +++ b/hreq-core/src/Hreq/Core/Client/HasResponse.hs @@ -6,13 +6,13 @@ {-# LANGUAGE CPP #-} module Hreq.Core.Client.HasResponse where -import Control.Monad (when, unless) +import Control.Monad (unless, when) import Control.Monad.Except -import Data.Kind import Data.Hlist +import Data.Kind +import qualified Data.List.NonEmpty as NE import Data.Proxy import Data.Singletons -import qualified Data.List.NonEmpty as NE #if MIN_VERSION_base(4,18,0) import GHC.TypeLits hiding (withKnownNat) #else @@ -147,7 +147,7 @@ decodeAsBody _ response = do . throwError $ UnsupportedContentType (NE.head accepts) response case mediaDecode ctypProxy (resBody response) of - Left err -> throwError $ DecodeFailure (unDecodeError err) response + Left err -> throwError $ DecodeFailure (unDecodeError err) response Right val -> pure val where ctypProxy :: Proxy ctyp diff --git a/hreq-core/src/Hreq/Core/Client/RunClient.hs b/hreq-core/src/Hreq/Core/Client/RunClient.hs index 83ae267..33f61e4 100644 --- a/hreq-core/src/Hreq/Core/Client/RunClient.hs +++ b/hreq-core/src/Hreq/Core/Client/RunClient.hs @@ -35,16 +35,16 @@ instance Monad (ClientPure state) where m >>= f = case m of RunClient r x -> setHttpRequest r $ f x - Throw e -> Throw e + Throw e -> Throw e instance Applicative (ClientPure state) where pure = RunClient defaultRequest f <*> x = case x of - Throw e -> Throw e + Throw e -> Throw e RunClient r y -> setHttpRequest r $ fmap ( $ y) f setHttpRequest :: Request -> ClientPure state a -> ClientPure state a setHttpRequest r h = case h of RunClient _ rs -> RunClient r rs - Throw e -> Throw e + Throw e -> Throw e