summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichaelSnoyman <>2016-09-14 15:23:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2016-09-14 15:23:00 (GMT)
commit19b7e1319bbf7e94d14a13c7a56cf4716f9f7e19 (patch)
treeea2c3b3b6895ed303a1aa5a69ef44ebf3f0c4a70
parentc8a7ad991481945f3490d4b345f2485102366b96 (diff)
version 2.2.22.2.2
-rw-r--r--ChangeLog.md8
-rw-r--r--Network/HTTP/Client/Conduit.hs2
-rw-r--r--Network/HTTP/Conduit.hs12
-rw-r--r--Network/HTTP/Simple.hs53
-rw-r--r--README.md2
-rw-r--r--http-conduit.cabal2
6 files changed, 71 insertions, 8 deletions
diff --git a/ChangeLog.md b/ChangeLog.md
index 4463696..b153370 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,3 +1,11 @@
+## 2.2.2
+
+* Add `httpNoBody` to `Network.HTTP.Simple`
+
+## 2.2.1
+
+* Add `httpSource` to `Network.HTTP.Simple`
+
## 2.2.0.1
* Doc fixes
diff --git a/Network/HTTP/Client/Conduit.hs b/Network/HTTP/Client/Conduit.hs
index 44c2ee9..d8da489 100644
--- a/Network/HTTP/Client/Conduit.hs
+++ b/Network/HTTP/Client/Conduit.hs
@@ -6,7 +6,7 @@
-- For most users, "Network.HTTP.Simple" is probably a better choice. For more
-- information, see:
--
--- <https://github.com/commercialhaskell/jump/blob/master/doc/http-client.md>.
+-- <https://haskell-lang.org/library/http-client>
--
-- For more information on using this module, please be sure to read the
-- documentation in the "Network.HTTP.Client" module.
diff --git a/Network/HTTP/Conduit.hs b/Network/HTTP/Conduit.hs
index 3f39393..579ff81 100644
--- a/Network/HTTP/Conduit.hs
+++ b/Network/HTTP/Conduit.hs
@@ -11,7 +11,7 @@
-- response bodies. For most users, this will be an easier place to start. You
-- can read the tutorial at:
--
--- https://github.com/commercialhaskell/jump/blob/master/doc/http-client.md
+-- <https://haskell-lang.org/library/http-client>
--
-- = Lower-level API
--
@@ -91,9 +91,13 @@
-- > request' <- parseRequest "http://example.com/secret-page"
-- > manager <- newManager tlsManagerSettings
-- > let request = request' { cookieJar = Just $ createCookieJar [cookie] }
--- > (fmap Just (httpLbs request manager)) `E.catch`
--- > (\(StatusCodeException s _ _) ->
--- > if statusCode s==403 then (putStrLn "login failed" >> return Nothing) else return Nothing)
+-- > fmap Just (httpLbs request manager) `E.catch`
+-- > (\ex -> case ex of
+-- > HttpExceptionRequest _ (StatusCodeException res _) ->
+-- > if statusCode (responseStatus res) == 403
+-- > then (putStrLn "login failed" >> return Nothing)
+-- > else return Nothing
+-- > _ -> E.throw ex)
--
-- Any network code on Windows requires some initialization, and the network
-- library provides withSocketsDo to perform it. Therefore, proper usage of
diff --git a/Network/HTTP/Simple.hs b/Network/HTTP/Simple.hs
index eb55e52..0d4dade 100644
--- a/Network/HTTP/Simple.hs
+++ b/Network/HTTP/Simple.hs
@@ -4,7 +4,7 @@
{-# LANGUAGE OverloadedStrings #-}
-- | Simplified interface for common HTTP client interactions. Tutorial
-- available at
--- <https://github.com/commercialhaskell/jump/blob/master/doc/http-client.md>.
+-- <https://haskell-lang.org/library/http-client>
--
-- Important note: 'H.Request' is an instance of 'Data.String.IsString', and
-- therefore recommended usage is to turn on @OverloadedStrings@, e.g.
@@ -18,9 +18,11 @@
module Network.HTTP.Simple
( -- * Perform requests
httpLBS
+ , httpNoBody
, httpJSON
, httpJSONEither
, httpSink
+ , httpSource
-- * Types
, H.Request
, H.Response
@@ -86,6 +88,7 @@ import qualified Data.Conduit.Attoparsec as C
import qualified Control.Monad.Catch as Catch
import qualified Network.HTTP.Types as H
import Data.Int (Int64)
+import Control.Monad.Trans.Resource (MonadResource)
-- | Perform an HTTP request and return the body as a lazy @ByteString@. Note
-- that the entire value will be read into memory at once (no lazy I\/O will be
@@ -97,6 +100,14 @@ httpLBS req = liftIO $ do
man <- H.getGlobalManager
H.httpLbs req man
+-- | Perform an HTTP request and ignore the response body.
+--
+-- @since 2.2.2
+httpNoBody :: MonadIO m => H.Request -> m (H.Response ())
+httpNoBody req = liftIO $ do
+ man <- H.getGlobalManager
+ H.httpNoBody req man
+
-- | Perform an HTTP request and parse the body as JSON. In the event of an
-- JSON parse errors, a 'JSONException' runtime exception will be thrown.
--
@@ -148,6 +159,46 @@ httpSink req sink = do
(\res -> bodyReaderSource (getResponseBody res)
C.$$ sink (fmap (const ()) res))
+-- | Perform an HTTP request, and get the response body as a Source.
+--
+-- The second argument to this function tells us how to make the
+-- Source from the Response itself. This allows you to perform actions
+-- with the status or headers, for example, in addition to the raw
+-- bytes themselves. If you just care about the response body, you can
+-- use 'getResponseBody' as the second argument here.
+--
+-- @
+-- \{\-# LANGUAGE OverloadedStrings \#\-}
+-- import Control.Monad.IO.Class (liftIO)
+-- import Control.Monad.Trans.Resource (runResourceT)
+-- import Data.Conduit (($$))
+-- import qualified Data.Conduit.Binary as CB
+-- import qualified Data.Conduit.List as CL
+-- import Network.HTTP.Simple
+-- import System.IO (stdout)
+--
+-- main :: IO ()
+-- main =
+-- runResourceT
+-- $ httpSource "http://httpbin.org/robots.txt" getSrc
+-- $$ CB.sinkHandle stdout
+-- where
+-- getSrc res = do
+-- liftIO $ print (getResponseStatus res, getResponseHeaders res)
+-- getResponseBody res
+-- @
+--
+-- @since 2.2.1
+httpSource :: (MonadResource m, MonadIO n)
+ => H.Request
+ -> (H.Response (C.ConduitM i S.ByteString n ())
+ -> C.ConduitM i o m r)
+ -> C.ConduitM i o m r
+httpSource req withRes = do
+ man <- liftIO H.getGlobalManager
+ C.bracketP (H.responseOpen req man) H.responseClose
+ (withRes . fmap bodyReaderSource)
+
-- | Alternate spelling of 'httpLBS'
--
-- @since 2.1.10
diff --git a/README.md b/README.md
index c769cea..2f95f50 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,6 @@ http-conduit
============
Full tutorial docs are available at:
-https://github.com/commercialhaskell/jump/blob/master/doc/http-client.md
+https://haskell-lang.org/library/http-client
The `Network.HTTP.Conduit.Browser` module has been moved to <http://hackage.haskell.org/package/http-conduit-browser/>
diff --git a/http-conduit.cabal b/http-conduit.cabal
index 445d68d..79b85f1 100644
--- a/http-conduit.cabal
+++ b/http-conduit.cabal
@@ -1,5 +1,5 @@
name: http-conduit
-version: 2.2.0.1
+version: 2.2.2
license: BSD3
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>