summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichaelSnoyman <>2018-07-02 05:58:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2018-07-02 05:58:00 (GMT)
commit238905e06040b35e475575e69ea4d994367a9a13 (patch)
tree6449c350d03bf177fa2214a8e6489fbc9f420390
parent72f5eafa149b627dcc850f3d7e7dfa5a24689abd (diff)
version 2.3.22.3.2
-rw-r--r--ChangeLog.md6
-rw-r--r--Network/HTTP/Simple.hs26
-rw-r--r--http-conduit.cabal2
-rw-r--r--test/CookieTest.hs8
4 files changed, 35 insertions, 7 deletions
diff --git a/ChangeLog.md b/ChangeLog.md
index 3f0d018..e943367 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,3 +1,9 @@
+## 2.3.2
+
+* Adds `parseRequestThrow`, `parseRequestThrow_`, and
+ `setRequestCheckStatus` to `Network.HTTP.Simple`.
+ See [#304](https://github.com/snoyberg/http-client/issues/304)
+
## 2.3.1
* Reexport Query from Network.HTTP.Types
diff --git a/Network/HTTP/Simple.hs b/Network/HTTP/Simple.hs
index 8099a4d..bac1b5e 100644
--- a/Network/HTTP/Simple.hs
+++ b/Network/HTTP/Simple.hs
@@ -38,6 +38,8 @@ module Network.HTTP.Simple
, H.defaultRequest
, H.parseRequest
, H.parseRequest_
+ , parseRequestThrow
+ , parseRequestThrow_
-- * Request lenses
-- ** Basics
, setRequestMethod
@@ -60,6 +62,7 @@ module Network.HTTP.Simple
, setRequestBodyURLEncoded
-- ** Special fields
, H.setRequestIgnoreStatus
+ , H.setRequestCheckStatus
, setRequestBasicAuth
, setRequestManager
, setRequestProxy
@@ -86,14 +89,14 @@ import Data.Aeson.Parser (json')
import qualified Data.Aeson.Types as A
import qualified Data.Aeson as A
import qualified Data.Traversable as T
-import Control.Exception (throwIO, Exception)
+import Control.Exception (throw, throwIO, Exception)
import Data.Typeable (Typeable)
import qualified Data.Conduit as C
import Data.Conduit (runConduit, (.|), ConduitM)
import qualified Data.Conduit.Attoparsec as C
import qualified Network.HTTP.Types as H
import Data.Int (Int64)
-import Control.Monad.Trans.Resource (MonadResource)
+import Control.Monad.Trans.Resource (MonadResource, MonadThrow)
import qualified Control.Exception as E (bracket)
import Data.Void (Void)
@@ -237,6 +240,25 @@ withResponse req withRes = withRunInIO $ \run -> do
H.responseClose
(run . withRes . fmap bodyReaderSource)
+-- | Same as 'parseRequest', except will throw an 'HttpException' in the
+-- event of a non-2XX response. This uses 'throwErrorStatusCodes' to
+-- implement 'checkResponse'.
+--
+-- Exactly the same as 'parseUrlThrow', but has a name that is more
+-- consistent with the other parseRequest functions.
+--
+-- @since 2.3.2
+parseRequestThrow :: MonadThrow m => String -> m HC.Request
+parseRequestThrow = HC.parseUrlThrow
+
+-- | Same as 'parseRequestThrow', but parse errors cause an impure
+-- exception. Mostly useful for static strings which are known to be
+-- correctly formatted.
+--
+-- @since 2.3.2
+parseRequestThrow_ :: String -> HC.Request
+parseRequestThrow_ = either throw id . HC.parseUrlThrow
+
-- | Alternate spelling of 'httpLBS'
--
-- @since 2.1.10
diff --git a/http-conduit.cabal b/http-conduit.cabal
index cf5652a..d442239 100644
--- a/http-conduit.cabal
+++ b/http-conduit.cabal
@@ -1,5 +1,5 @@
name: http-conduit
-version: 2.3.1
+version: 2.3.2
license: BSD3
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
diff --git a/test/CookieTest.hs b/test/CookieTest.hs
index 3222b74..4fd6f1c 100644
--- a/test/CookieTest.hs
+++ b/test/CookieTest.hs
@@ -139,7 +139,7 @@ testRemoveCookie = assertEqual "Removing a cookie works"
(Just default_cookie, createCookieJar []) (removeExistingCookieFromCookieJar default_cookie $ createCookieJar [default_cookie])
testRemoveNonexistantCookie :: IO ()
-testRemoveNonexistantCookie = assertEqual "Removing a nonexistant cookie doesn't work"
+testRemoveNonexistantCookie = assertEqual "Removing a nonexistent cookie doesn't work"
(Nothing, createCookieJar [default_cookie]) (removeExistingCookieFromCookieJar (default_cookie {cookie_name = fromString "key2"}) $ createCookieJar [default_cookie])
testRemoveCorrectCookie :: IO ()
@@ -379,7 +379,7 @@ testReceiveSetCookiePath = assertEqual "Path gets set correctly"
where set_cookie = default_set_cookie {setCookiePath = Just $ fromString "/a/path"}
testReceiveSetCookieNoPath :: IO ()
-testReceiveSetCookieNoPath = assertEqual "Path gets set correctly when nonexistant"
+testReceiveSetCookieNoPath = assertEqual "Path gets set correctly when nonexistent"
(fromString "/a/path/to") (cookie_path $ head $ destroyCookieJar $ receiveSetCookie set_cookie request default_time True $ createCookieJar [])
where set_cookie = default_set_cookie {setCookiePath = Nothing}
request = default_request {HC.path = fromString "/a/path/to/nowhere"}
@@ -487,7 +487,7 @@ equalityTests = do
removeTests :: Spec
removeTests = do
it "Removing a cookie works" testRemoveCookie
- it "Removing a nonexistant cookie doesn't work" testRemoveNonexistantCookie
+ it "Removing a nonexistent cookie doesn't work" testRemoveNonexistantCookie
it "Removing the correct cookie" testRemoveCorrectCookie
evictionTests :: Spec
@@ -528,7 +528,7 @@ receivingTests = do
it "Expiry gets set based on max age if no expiry is given" testReceiveSetCookieNoExpiry
it "Expiry gets set based on given value if no max age is given" testReceiveSetCookieNoMaxAge
it "Expiry gets set to a future date if no expiry and no max age are given" testReceiveSetCookieNoExpiryNoMaxAge
- it "Path gets set correctly when nonexistant" testReceiveSetCookieNoPath
+ it "Path gets set correctly when nonexistent" testReceiveSetCookieNoPath
it "Path gets set correctly" testReceiveSetCookiePath
it "Creation time gets set correctly" testReceiveSetCookieCreationTime
it "Last access time gets set correctly" testReceiveSetCookieAccessTime