packages feed

http-client 0.4.10 → 0.4.11

raw patch · 5 files changed

+41/−24 lines, 5 files

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+## 0.4.11++* Ignore the 'Content-Length' header if the body contains chunked data [#115](https://github.com/snoyberg/http-client/pull/115)+ ## 0.4.10  * Expect: 100-continue [#114](https://github.com/snoyberg/http-client/pull/114)
Network/HTTP/Client/Response.hs view
@@ -98,13 +98,9 @@         toPut = Just "close" /= lookup "connection" hs && version > W.HttpVersion 1 0         cleanup bodyConsumed = connRelease $ if toPut && bodyConsumed then Reuse else DontReuse -    when (isJust mcl && isChunked) $ do-        cleanup False-        throwIO ResponseLengthAndChunkingBothUsed-     body <-         -- RFC 2616 section 4.4_1 defines responses that must not include a body-        if hasNoBody method (W.statusCode s) || mcl == Just 0+        if hasNoBody method (W.statusCode s) || (mcl == Just 0 && not isChunked)             then do                 cleanup True                 return brEmpty
Network/HTTP/Client/Types.hs view
@@ -115,12 +115,11 @@                    -- ^ Environment name and value                    --                    -- Since 0.4.7-                    | ResponseLengthAndChunkingBothUsed                    -- ^ Detect a case where both the @content-length@ header-                   -- and @transfer-encoding: chunked@ are used.+                   -- and @transfer-encoding: chunked@ are used. Since 0.4.8.                    ---                   -- Since 0.4.8+                   -- Since 0.4.11 this exception isn't thrown anymore.     deriving (Show, T.Typeable) instance Exception HttpException 
http-client.cabal view
@@ -1,5 +1,5 @@ name:                http-client-version:             0.4.10+version:             0.4.11 synopsis:            An HTTP client engine, intended as a base layer for more user-friendly packages. description:         Hackage documentation generation is not reliable. For up to date documentation, please see: <http://www.stackage.org/package/http-client>. homepage:            https://github.com/snoyberg/http-client
test-nonet/Network/HTTP/ClientSpec.hs view
@@ -11,6 +11,7 @@ import           Test.Hspec import qualified Data.Streaming.Network    as N import qualified Data.ByteString           as S+import qualified Data.ByteString.Lazy      as SL import           Data.ByteString.Lazy.Char8 () -- orphan instance  main :: IO ()@@ -74,7 +75,16 @@ -- that misreporting like https://github.com/snoyberg/http-client/issues/108 -- doesn't occur. lengthAndChunked :: (Int -> IO a) -> IO a-lengthAndChunked inner = bracket+lengthAndChunked = serveWith "HTTP/1.1 200 OK\r\ncontent-length: 24\r\ntransfer-encoding: chunked\r\n\r\n4\r\nWiki\r\n5\r\npedia\r\ne\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n"++lengthZeroAndChunked :: (Int -> IO a) -> IO a+lengthZeroAndChunked = serveWith "HTTP/1.1 200 OK\r\ncontent-length: 0\r\ntransfer-encoding: chunked\r\n\r\n4\r\nWiki\r\n5\r\npedia\r\ne\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n"++lengthZeroAndChunkZero :: (Int -> IO a) -> IO a+lengthZeroAndChunkZero = serveWith "HTTP/1.1 200 OK\r\ncontent-length: 0\r\ntransfer-encoding: chunked\r\n\r\n0\r\n\r\n"++serveWith :: S.ByteString -> (Int -> IO a) -> IO a+serveWith resp inner = bracket     (N.bindRandomPortTCP "*4")     (sClose . snd)     $ \(port, lsocket) -> withAsync@@ -89,8 +99,15 @@                     then return ()                     else readHeaders bs         readHeaders S.empty-        N.appWrite ad "HTTP/1.1 200 OK\r\ncontent-length: 0\r\ntransfer-encoding: chunked\r\n\r\n0"+        N.appWrite ad resp +getChunkedResponse :: Int -> Manager -> IO (Response SL.ByteString)+getChunkedResponse port' man = flip httpLbs man "http://localhost"+  { port        = port'+  , checkStatus = \_ _ _ -> Nothing+  , requestBody = RequestBodyStreamChunked ($ return (S.replicate 100000 65))+  }+ spec :: Spec spec = describe "Client" $ do     describe "fails on empty hostnames #40" $ do@@ -140,20 +157,21 @@      it "early close on a 413" $ earlyClose413 $ \port' -> do         withManager defaultManagerSettings $ \man -> do-            res <- flip httpLbs man "http://localhost"-                { port = port'-                , checkStatus = \_ _ _ -> Nothing-                , requestBody = RequestBodyStreamChunked-                    ($ return (S.replicate 100000 65))-                }+            res <- getChunkedResponse port' man             responseBody res `shouldBe` "goodbye"             responseStatus res `shouldBe` status413 -    it "length and chunking #108" $ lengthAndChunked $ \port' -> do+    it "length zero and chunking zero #108" $ lengthZeroAndChunkZero $ \port' -> do         withManager defaultManagerSettings $ \man -> do-            (void $ flip httpLbs man "http://localhost"-                { port = port'-                , checkStatus = \_ _ _ -> Nothing-                , requestBody = RequestBodyStreamChunked-                    ($ return (S.replicate 100000 65))-                }) `shouldThrow` (\e -> case e of { ResponseLengthAndChunkingBothUsed -> True; _ -> False})+            res <- getChunkedResponse port' man+            responseBody res `shouldBe` ""++    it "length zero and chunking" $ lengthZeroAndChunked $ \port' -> do+        withManager defaultManagerSettings $ \man -> do+            res <- getChunkedResponse port' man+            responseBody res `shouldBe` "Wikipedia in\r\n\r\nchunks."++    it "length and chunking" $ lengthAndChunked $ \port' -> do+        withManager defaultManagerSettings $ \man -> do+            res <- getChunkedResponse port' man+            responseBody res `shouldBe` "Wikipedia in\r\n\r\nchunks."