summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichaelSnoyman <>2017-07-11 16:45:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2017-07-11 16:45:00 (GMT)
commit6616ee83ecce49b28e876124fe1d6ae72d72e63d (patch)
tree74fc4f258f3bc5356b6bf060b3703ad65cca092b
parent98beea5936395d0eaa3977b8d63d9e2cf313077e (diff)
version 2.2.3.22.2.3.2
-rw-r--r--ChangeLog.md4
-rw-r--r--Network/HTTP/Conduit.hs17
-rw-r--r--Network/HTTP/Simple.hs10
-rw-r--r--http-conduit.cabal2
-rw-r--r--test/main.hs3
5 files changed, 14 insertions, 22 deletions
diff --git a/ChangeLog.md b/ChangeLog.md
index 97b50f9..556fa0c 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,3 +1,7 @@
+## 2.2.3.2
+
+* Add proper headers for `httpJSON` and `httpJSONEither` [#284](https://github.com/snoyberg/http-client/issues/284)
+
## 2.2.3.1
* Minor README improvement
diff --git a/Network/HTTP/Conduit.hs b/Network/HTTP/Conduit.hs
index 579ff81..978807e 100644
--- a/Network/HTTP/Conduit.hs
+++ b/Network/HTTP/Conduit.hs
@@ -87,7 +87,7 @@
-- > , cookie_http_only = False
-- > }
-- >
--- > main = withSocketsDo $ do
+-- > main = do
-- > request' <- parseRequest "http://example.com/secret-page"
-- > manager <- newManager tlsManagerSettings
-- > let request = request' { cookieJar = Just $ createCookieJar [cookie] }
@@ -99,19 +99,6 @@
-- > 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
--- this library will always involve calling that function at some point. The
--- best approach is to simply call them at the beginning of your main function,
--- such as:
---
--- > import Network.HTTP.Conduit
--- > import qualified Data.ByteString.Lazy as L
--- > import Network (withSocketsDo)
--- >
--- > main = withSocketsDo
--- > $ simpleHttp "http://www.haskell.org/" >>= L.putStr
---
-- Cookies are implemented according to RFC 6265.
--
-- Note that by default, the functions in this package will throw exceptions
@@ -124,7 +111,7 @@
-- > import Network
-- >
-- > main :: IO ()
--- > main = withSocketsDo $ do
+-- > main = do
-- > request' <- parseRequest "http://www.yesodweb.com/does-not-exist"
-- > let request = request' { checkStatus = \_ _ _ -> Nothing }
-- > manager <- newManager tlsManagerSettings
diff --git a/Network/HTTP/Simple.hs b/Network/HTTP/Simple.hs
index 0f883f5..0f39212 100644
--- a/Network/HTTP/Simple.hs
+++ b/Network/HTTP/Simple.hs
@@ -15,6 +15,8 @@
-- >
-- > main :: IO ()
-- > main = httpLBS "http://example.com" >>= L8.putStrLn
+--
+-- The `Data.String.IsString` instance uses `H.parseRequest` behind the scenes and inherits its behavior.
module Network.HTTP.Simple
( -- * Perform requests
httpLBS
@@ -123,17 +125,17 @@ httpJSON req = liftIO $ httpJSONEither req >>= T.mapM (either throwIO return)
httpJSONEither :: (MonadIO m, FromJSON a)
=> H.Request
-> m (H.Response (Either JSONException a))
-httpJSONEither req =
- liftIO $ httpSink req sink
+httpJSONEither req = liftIO $ httpSink req' sink
where
+ req' = addRequestHeader H.hAccept "application/json" req
sink orig = fmap (\x -> fmap (const x) orig) $ do
eres1 <- C.sinkParserEither json'
case eres1 of
- Left e -> return $ Left $ JSONParseException req orig e
+ Left e -> return $ Left $ JSONParseException req' orig e
Right value ->
case A.fromJSON value of
A.Error e -> return $ Left $ JSONConversionException
- req (fmap (const value) orig) e
+ req' (fmap (const value) orig) e
A.Success x -> return $ Right x
-- | An exception that can occur when parsing JSON
diff --git a/http-conduit.cabal b/http-conduit.cabal
index 47ab131..f04989d 100644
--- a/http-conduit.cabal
+++ b/http-conduit.cabal
@@ -1,5 +1,5 @@
name: http-conduit
-version: 2.2.3.1
+version: 2.2.3.2
license: BSD3
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
diff --git a/test/main.hs b/test/main.hs
index f799ddd..38b617e 100644
--- a/test/main.hs
+++ b/test/main.hs
@@ -20,7 +20,6 @@ import Network.HTTP.Types
import Control.Exception.Lifted (try, SomeException, bracket, onException, IOException)
import qualified Data.IORef as I
import qualified Control.Exception as E (catch)
-import Network (withSocketsDo)
import Network.Socket (sClose)
import qualified Network.BSD
import CookieTest (cookieTest)
@@ -172,7 +171,7 @@ withAppTls' app' f = do
sendResponse res
main :: IO ()
-main = withSocketsDo $ do
+main = do
mapM_ (`hSetBuffering` LineBuffering) [stdout, stderr]
hspec $ do
cookieTest