http-client 0.3.2 → 0.3.2.1
raw patch · 4 files changed
+41/−8 lines, 4 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Network.HTTP.Client.Internal: connectionDropTillBlankLine :: Connection -> IO ()
Files
- Network/HTTP/Client/Connection.hs +8/−0
- Network/HTTP/Client/Headers.hs +1/−5
- http-client.cabal +1/−1
- test/Network/HTTP/ClientSpec.hs +31/−2
Network/HTTP/Client/Connection.hs view
@@ -4,6 +4,7 @@ module Network.HTTP.Client.Connection ( connectionReadLine , connectionReadLineWith+ , connectionDropTillBlankLine , dummyConnection , openSocketConnection , makeConnection@@ -20,12 +21,19 @@ import qualified Control.Exception as E import qualified Data.ByteString as S import Data.Word (Word8)+import Data.Function (fix) connectionReadLine :: Connection -> IO ByteString connectionReadLine conn = do bs <- connectionRead conn when (S.null bs) $ throwIO IncompleteHeaders connectionReadLineWith conn bs++-- | Keep dropping input until a blank line is found.+connectionDropTillBlankLine :: Connection -> IO ()+connectionDropTillBlankLine conn = fix $ \loop -> do+ bs <- connectionReadLine conn+ unless (S.null bs) loop connectionReadLineWith :: Connection -> ByteString -> IO ByteString connectionReadLineWith conn bs0 =
Network/HTTP/Client/Headers.hs view
@@ -38,12 +38,8 @@ status@(code, _) <- connectionReadLineWith conn bs >>= parseStatus 3 if code == status100- then newline ExpectedBlankAfter100Continue >> getStatusLine+ then connectionDropTillBlankLine conn >> getStatusLine else return status-- newline exc = do- line <- connectionReadLine conn- unless (S.null line) $ throwIO exc parseStatus :: Int -> S.ByteString -> IO (Status, HttpVersion) parseStatus i bs | S.null bs && i > 0 = connectionReadLine conn >>= parseStatus (i - 1)
http-client.cabal view
@@ -1,5 +1,5 @@ name: http-client-version: 0.3.2+version: 0.3.2.1 synopsis: An HTTP client engine, intended as a base layer for more user-friendly packages. description: This codebase has been refactored from http-conduit. homepage: https://github.com/snoyberg/http-client
test/Network/HTTP/ClientSpec.hs view
@@ -5,13 +5,14 @@ import Control.Concurrent.Async (withAsync) import Control.Exception (bracket) import Control.Monad (forever, replicateM_)-import Network (PortID (PortNumber), listenOn)+import Network (PortID (PortNumber), listenOn, withSocketsDo) import Network.HTTP.Client import Network.HTTP.Types (status200) import Network.Socket (accept, sClose) import Network.Socket.ByteString (recv, sendAll) import Test.Hspec import qualified Data.Streaming.Network as N+import qualified Data.ByteString as S main :: IO () main = hspec spec@@ -32,9 +33,28 @@ N.appWrite ad "hello\r\n" threadDelay 10000 +bad100Server :: Bool -- ^ include extra headers?+ -> (Int -> IO a) -> IO a+bad100Server extraHeaders inner = bracket+ (N.bindRandomPortTCP "*4")+ (sClose . snd)+ $ \(port, lsocket) -> withAsync+ (N.runTCPServer (N.serverSettingsTCPSocket lsocket) app)+ (const $ inner port)+ where+ app ad = do+ forkIO $ forever $ N.appRead ad+ forever $ do+ N.appWrite ad $ S.concat+ [ "HTTP/1.1 100 Continue\r\n"+ , if extraHeaders then "foo:bar\r\nbaz: bin\r\n" else ""+ , "\r\nHTTP/1.1 200 OK\r\ncontent-length: 5\r\n\r\nhello\r\n"+ ]+ threadDelay 10000+ spec :: Spec spec = describe "Client" $ do- it "works" $ do+ it "works" $ withSocketsDo $ do req <- parseUrl "http://www.yesodweb.com/" man <- newManager defaultManagerSettings res <- httpLbs req man@@ -74,3 +94,12 @@ case e of FailedConnectionException2 "127.0.0.1" port' False _ -> port == port' _ -> False++ describe "extra headers after 100 #49" $ do+ let test x = it (show x) $ bad100Server x $ \port -> do+ req <- parseUrl $ "http://127.0.0.1:" ++ show port+ withManager defaultManagerSettings $ \man -> replicateM_ 10 $ do+ x <- httpLbs req man+ responseBody x `shouldBe` "hello"+ test False+ test True