packages feed

req-conduit 1.0.0 → 1.0.1

raw patch · 7 files changed

+158/−143 lines, 7 filesdep ~basedep ~conduitdep ~resourcet

Dependency ranges changed: base, conduit, resourcet, transformers

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+## Req Conduit 1.0.1++* Builds with GHC 8.8, 8.10, 9.0 and the newest nightly Stackage snapshots.++* Dropped support for GHC 8.6 and older.+ ## Req Conduit 1.0.0  * This version is to be used with Req 1.0.0 and later.
LICENSE.md view
@@ -1,4 +1,4 @@-Copyright © 2016–2017 Mark Karpov+Copyright © 2016–present Mark Karpov  All rights reserved. 
Network/HTTP/Req/Conduit.hs view
@@ -1,6 +1,6 @@ -- | -- Module      :  Network.HTTP.Req.Conduit--- Copyright   :  © 2016–2017 Mark Karpov, Michael Snoyman+-- Copyright   :  © 2016–present Mark Karpov, Michael Snoyman -- License     :  BSD 3 clause -- -- Maintainer  :  Mark Karpov <markkarpov92@gmail.com>@@ -12,44 +12,34 @@ -- -- The package re-uses some pieces of code from the @http-conduit@ package, -- but not to the extent that depending on that package becomes reasonable.--{-# LANGUAGE CPP               #-}-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE RankNTypes        #-}-{-# LANGUAGE TypeFamilies      #-}--#if __GLASGOW_HASKELL__ <  710-{-# LANGUAGE ConstraintKinds #-}-#endif- module Network.HTTP.Req.Conduit   ( -- * Streaming request bodies-    ReqBodySource (..)+    ReqBodySource (..),+     -- * Streaming response bodies     -- $streaming-response-  , responseBodySource )+    responseBodySource,+  ) where  import Control.Monad import Control.Monad.IO.Class (MonadIO (..)) import Data.ByteString (ByteString)-import Data.Conduit (Source, ($$+), ($$++), await, yield)+import qualified Data.ByteString as B+import Data.Conduit (ConduitT, await, yield, ($$+), ($$++)) import Data.IORef import Data.Int (Int64)-import Network.HTTP.Req-import qualified Data.ByteString     as B-import qualified Data.Conduit        as C import qualified Network.HTTP.Client as L+import Network.HTTP.Req  ---------------------------------------------------------------------------- -- Request bodies  -- | This body option streams contents of request body from the given--- 'C.Source'. The 'Int64' value is size of the data in bytes.+-- source. The 'Int64' value is size of the data in bytes. -- -- Using of this body option does not set the @Content-Type@ header.--data ReqBodySource = ReqBodySource Int64 (C.Source IO ByteString)+data ReqBodySource = ReqBodySource Int64 (ConduitT () ByteString IO ())  instance HttpBody ReqBodySource where   getRequestBody (ReqBodySource size src) =@@ -85,8 +75,8 @@ -- approach is only viable when the entire pipeline can be run in 'IO' monad -- (in the function that is the last argument of 'reqBr'). ----- If you need to use a more complex monad, you'll need to deal with the--- lower-level function 'req'':+-- If you need to use a more complex monad, use the lower-level function+-- 'req'': -- -- > {-# LANGUAGE FlexibleInstances #-} -- > {-# LANGUAGE OverloadedStrings #-}@@ -117,21 +107,22 @@ -- 'req'' does not open\/close connections, handle exceptions, and does not -- perform retrying though, so you're on your own. --- | Turn @'L.Response' 'L.BodyReader'@ into a 'C.Producer'.+-- | Turn @'L.Response' 'L.BodyReader'@ into a producer. -- -- @since 1.0.0--responseBodySource :: MonadIO m-  => L.Response L.BodyReader -- ^ Response with body reader-  -> C.Producer m ByteString -- ^ Response body as a 'C.Producer'+responseBodySource ::+  MonadIO m =>+  -- | Response with body reader+  L.Response L.BodyReader ->+  -- | Response body as a 'C.Producer'+  ConduitT i ByteString m () responseBodySource = bodyReaderSource . L.responseBody  ---------------------------------------------------------------------------- -- Helpers  -- | This is taken from "Network.HTTP.Client.Conduit" without modifications.--srcToPopperIO :: Source IO ByteString -> L.GivesPopper ()+srcToPopperIO :: ConduitT () ByteString IO () -> L.GivesPopper () srcToPopperIO src f = do   (rsrc0, ()) <- src $$+ return ()   irsrc <- newIORef rsrc0@@ -143,13 +134,12 @@         case mres of           Nothing -> return B.empty           Just bs-              | B.null bs -> popper-              | otherwise -> return bs+            | B.null bs -> popper+            | otherwise -> return bs   f popper  -- | This is taken from "Network.HTTP.Client.Conduit" without modifications.--bodyReaderSource :: MonadIO m => L.BodyReader -> C.Producer m ByteString+bodyReaderSource :: MonadIO m => L.BodyReader -> ConduitT i ByteString m () bodyReaderSource br = go   where     go = do
README.md view
@@ -4,8 +4,7 @@ [![Hackage](https://img.shields.io/hackage/v/req-conduit.svg?style=flat)](https://hackage.haskell.org/package/req-conduit) [![Stackage Nightly](http://stackage.org/package/req-conduit/badge/nightly)](http://stackage.org/nightly/package/req-conduit) [![Stackage LTS](http://stackage.org/package/req-conduit/badge/lts)](http://stackage.org/lts/package/req-conduit)-[![Build Status](https://travis-ci.org/mrkkrp/req-conduit.svg?branch=master)](https://travis-ci.org/mrkkrp/req-conduit)-[![Coverage Status](https://coveralls.io/repos/mrkkrp/req-conduit/badge.svg?branch=master&service=github)](https://coveralls.io/github/mrkkrp/req-conduit?branch=master)+![CI](https://github.com/mrkkrp/req-conduit/workflows/CI/badge.svg?branch=master)  This library extends functionality of the [`req`](https://hackage.haskell.org/package/req) package with@@ -17,10 +16,10 @@ Issues, bugs, and questions may be reported in [the GitHub issue tracker for this project](https://github.com/mrkkrp/req-conduit/issues). -Pull requests are also welcome and will be reviewed quickly.+Pull requests are also welcome.  ## License -Copyright © 2016–2017 Mark Karpov, Michael Snoyman+Copyright © 2016–present Mark Karpov, Michael Snoyman  Distributed under BSD 3 clause license.
httpbin-tests/Network/HTTP/Req/ConduitSpec.hs view
@@ -1,40 +1,39 @@-{-# LANGUAGE CPP                  #-}-{-# LANGUAGE DataKinds            #-}-{-# LANGUAGE FlexibleInstances    #-}-{-# LANGUAGE OverloadedStrings    #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-orphans #-} -module Network.HTTP.Req.ConduitSpec-  ( spec )-where+module Network.HTTP.Req.ConduitSpec (spec) where  import Control.Exception (throwIO) import Control.Monad-import Data.Conduit ((.|), runConduitRes)+import qualified Data.ByteString as B+import Data.Conduit (runConduitRes, (.|))+import qualified Data.Conduit.Binary as CB+import qualified Data.Conduit.List as CL import Data.Int (Int64) import Network.HTTP.Req import Network.HTTP.Req.Conduit import System.IO (Handle) import System.IO.Temp import Test.Hspec-import qualified Data.ByteString     as B-import qualified Data.Conduit.Binary as CB-import qualified Data.Conduit.List   as CL -#if !MIN_VERSION_base(4,8,0)-import Data.Monoid-#endif- spec :: Spec spec = do-   describe "streaming 10 M request" $     it "works" $ do       let size :: Int64           size = 10 * 1024 * 1024           src = CL.replicate (10 * 1024) (B.replicate 1024 0)-      void (req POST (httpbin /: "post")-        (ReqBodySource size src) ignoreResponse mempty) :: IO ()+      void+        ( req+            POST+            (httpbin /: "post")+            (ReqBodySource size src)+            ignoreResponse+            mempty+        ) ::+        IO ()    describe "streaming 10 M response" $     it "works" $ do@@ -45,7 +44,7 @@             size = 10 * 1024 * 1024         reqBr GET (httpbin /: "stream-bytes" /~ size) NoReqBody mempty $ \r ->           runConduitRes $-             responseBodySource r .| CB.sinkHandle h+            responseBodySource r .| CB.sinkHandle h  ---------------------------------------------------------------------------- -- Instances@@ -57,6 +56,5 @@ -- Helpers  -- | 'Url' representing <https://httpbin.org>.- httpbin :: Url 'Https httpbin = https "httpbin.org"
req-conduit.cabal view
@@ -1,80 +1,98 @@-name:                 req-conduit-version:              1.0.0-cabal-version:        >= 1.18-tested-with:          GHC==7.10.3, GHC==8.0.2, GHC==8.2.2-license:              BSD3-license-file:         LICENSE.md-author:               Mark Karpov <markkarpov92@gmail.com>, Michael Snoyman <michael@snoyman.com>-maintainer:           Mark Karpov <markkarpov92@gmail.com>-homepage:             https://github.com/mrkkrp/req-conduit-bug-reports:          https://github.com/mrkkrp/req-conduit/issues-category:             Network, Web, Conduit-synopsis:             Conduit helpers for the req HTTP client library-build-type:           Simple-description:          Conduit helpers for the req HTTP client library.-extra-doc-files:      CHANGELOG.md-                    , README.md+cabal-version:   1.18+name:            req-conduit+version:         1.0.1+license:         BSD3+license-file:    LICENSE.md+maintainer:      Mark Karpov <markkarpov92@gmail.com>+author:+    Mark Karpov <markkarpov92@gmail.com>, Michael Snoyman <michael@snoyman.com> +tested-with:     ghc ==8.8.4 ghc ==8.10.5 ghc ==9.0.1+homepage:        https://github.com/mrkkrp/req-conduit+bug-reports:     https://github.com/mrkkrp/req-conduit/issues+synopsis:        Conduit helpers for the req HTTP client library+description:     Conduit helpers for the req HTTP client library.+category:        Network, Web, Conduit+build-type:      Simple+extra-doc-files:+    CHANGELOG.md+    README.md+ source-repository head-  type:               git-  location:           https://github.com/mrkkrp/req-conduit.git+    type:     git+    location: https://github.com/mrkkrp/req-conduit.git  flag dev-  description:        Turn on development settings.-  manual:             True-  default:            False+    description: Turn on development settings.+    default:     False+    manual:      True  library-  build-depends:      base             >= 4.8   && < 5.0-                    , bytestring       >= 0.2   && < 0.11-                    , conduit          >= 1.2.8 && < 1.3-                    , http-client      >= 0.5   && < 0.6-                    , req              >= 1.0   && < 2.0-                    , resourcet        >= 1.1   && < 1.2-                    , transformers     >= 0.4   && < 0.6-  exposed-modules:    Network.HTTP.Req.Conduit-  if flag(dev)-    ghc-options:      -Wall -Werror-  else-    ghc-options:      -O2 -Wall-  default-language:   Haskell2010+    exposed-modules:  Network.HTTP.Req.Conduit+    default-language: Haskell2010+    build-depends:+        base >=4.13 && <5.0,+        bytestring >=0.2 && <0.12,+        conduit >=1.3 && <1.4,+        http-client >=0.5 && <0.8,+        req >=1.0 && <4.0,+        resourcet >=1.1 && <1.3,+        transformers >=0.4 && <0.6 +    if flag(dev)+        ghc-options: -Wall -Werror++    else+        ghc-options: -O2 -Wall++    if flag(dev)+        ghc-options:+            -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns+            -Wnoncanonical-monad-instances+ test-suite httpbin-tests-  main-is:            Spec.hs-  other-modules:      Network.HTTP.Req.ConduitSpec-  hs-source-dirs:     httpbin-tests-  type:               exitcode-stdio-1.0-  build-depends:      base             >= 4.8   && < 5.0-                    , bytestring       >= 0.2   && < 0.11-                    , conduit          >= 1.2.8 && < 1.3-                    , conduit-extra    >= 1.1.10 && < 1.3-                    , hspec            >= 2.0   && < 3.0-                    , req              >= 1.0   && < 2.0-                    , req-conduit-                    , resourcet        >= 1.1   && < 1.2-                    , temporary        >= 1.1   && < 1.3-                    , transformers     >= 0.4   && < 0.6-  if flag(dev)-    ghc-options:      -Wall -Werror-  else-    ghc-options:      -O2 -Wall-  default-language:   Haskell2010+    type:             exitcode-stdio-1.0+    main-is:          Spec.hs+    build-tools:      hspec-discover >=2.0 && <3.0+    hs-source-dirs:   httpbin-tests+    other-modules:    Network.HTTP.Req.ConduitSpec+    default-language: Haskell2010+    build-depends:+        base >=4.13 && <5.0,+        bytestring >=0.2 && <0.12,+        conduit >=1.3 && <1.4,+        conduit-extra >=1.1.10 && <1.4,+        hspec >=2.0 && <3.0,+        req >=1.0 && <4.0,+        req-conduit,+        resourcet >=1.1 && <1.3,+        temporary >=1.1 && <1.4,+        transformers >=0.4 && <0.6 +    if flag(dev)+        ghc-options: -Wall -Werror++    else+        ghc-options: -O2 -Wall+ benchmark weigh-bench-  main-is:            Main.hs-  hs-source-dirs:     weigh-bench-  type:               exitcode-stdio-1.0-  build-depends:      base             >= 4.8   && < 5.0-                    , bytestring       >= 0.2   && < 0.11-                    , conduit          >= 1.2.8 && < 1.3-                    , conduit-extra    >= 1.1.10 && < 1.3-                    , req              >= 1.0   && < 2.0-                    , req-conduit-                    , resourcet        >= 1.1   && < 1.2-                    , temporary        >= 1.1   && < 1.3-                    , weigh            >= 0.0.4-  if flag(dev)-    ghc-options:      -O2 -Wall -Werror-  else-    ghc-options:      -O2 -Wall-  default-language:   Haskell2010+    type:             exitcode-stdio-1.0+    main-is:          Main.hs+    hs-source-dirs:   weigh-bench+    default-language: Haskell2010+    build-depends:+        base >=4.13 && <5.0,+        bytestring >=0.2 && <0.12,+        conduit >=1.3 && <1.4,+        conduit-extra >=1.1.10 && <1.4,+        req >=1.0 && <4.0,+        req-conduit,+        resourcet >=1.1 && <1.3,+        temporary >=1.1 && <1.4,+        weigh >=0.0.4++    if flag(dev)+        ghc-options: -O2 -Wall -Werror++    else+        ghc-options: -O2 -Wall
weigh-bench/Main.hs view
@@ -1,29 +1,29 @@-{-# LANGUAGE DataKinds            #-}-{-# LANGUAGE FlexibleInstances    #-}-{-# LANGUAGE OverloadedStrings    #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-orphans #-}  module Main (main) where  import Control.Exception (throwIO) import Control.Monad-import Data.Conduit ((.|), runConduitRes)+import qualified Data.ByteString as B+import Data.Conduit (runConduitRes, (.|))+import qualified Data.Conduit.Binary as CB+import qualified Data.Conduit.List as CL import Data.Int (Int64) import Network.HTTP.Req import Network.HTTP.Req.Conduit import System.IO.Temp import Weigh-import qualified Data.ByteString     as B-import qualified Data.Conduit.Binary as CB-import qualified Data.Conduit.List   as CL  main :: IO () main = mainWith $ do   setColumns [Case, Allocated, GCs, Max]-  io "streaming 1 M request  body" bigRequest  (1 * 1024 * 1024)-  io "streaming 2 M request  body" bigRequest  (2 * 1024 * 1024)-  io "streaming 4 M request  body" bigRequest  (4 * 1024 * 1024)-  io "streaming 8 M request  body" bigRequest  (8 * 1024 * 1024)+  io "streaming 1 M request  body" bigRequest (1 * 1024 * 1024)+  io "streaming 2 M request  body" bigRequest (2 * 1024 * 1024)+  io "streaming 4 M request  body" bigRequest (4 * 1024 * 1024)+  io "streaming 8 M request  body" bigRequest (8 * 1024 * 1024)   io "streaming 1 M response body" bigResponse (1 * 1024 * 1024)   io "streaming 2 M response body" bigResponse (2 * 1024 * 1024)   io "streaming 4 M response body" bigResponse (4 * 1024 * 1024)@@ -31,11 +31,16 @@  bigRequest :: Int64 -> IO () bigRequest size' = do-  let size  = (size' `quot` 1024) * 1024+  let size = (size' `quot` 1024) * 1024       chunk = B.replicate 1024 0   let src = CL.replicate (fromIntegral size `quot` 1024) chunk-  void $ req POST (httpbin /: "post")-    (ReqBodySource size src) ignoreResponse mempty+  void $+    req+      POST+      (httpbin /: "post")+      (ReqBodySource size src)+      ignoreResponse+      mempty  bigResponse :: Int -> IO () bigResponse size = withSystemTempFile "req-conduit" $ \_ h ->@@ -53,6 +58,5 @@ -- Helpers  -- | 'Url' representing <https://httpbin.org>.- httpbin :: Url 'Https httpbin = https "httpbin.org"