on master help sign in
Fix bug with chunk boundaries snoyberg/http-client#58
commita0a0567d0e673aad2f6431099a269601a7d5363c authorMichael Snoyman <michael@snoyman.com> dateSun 15 Jun 2014, 10:06 (12 years ago) parent8c0c0c4
3 files changed+29−2
warp/Network/Wai/Handler/Warp/Conduit.hs+7−1 warp/test/ConduitSpec.hs+21 warp/warp.cabal+1−1
warp/Network/Wai/Handler/Warp/Conduit.hs+7−1
@@ -161,7 +161,13 @@ readCSource (CSource src ref) = do
161161 let w =
162162 S.foldl' (\i c -> i * 16 + fromIntegral (hexToWord c)) 0
163163 $ S.takeWhile isHexDigit x
164− withLen w $ S.drop 1 y
164+
165+ let y' = S.drop 1 y
166+ y'' <-
167+ if S.null y'
168+ then readSource src
169+ else return y'
170+ withLen w y''
165171
166172 hexToWord w
167173 | w < 58 = w - 48
warp/test/ConduitSpec.hs+21
@@ -42,5 +42,26 @@ spec = describe "conduit" $ do
4242 x <- replicateM 15 $ readCSource csrc
4343 S.concat x `shouldBe` "12345678"
4444
45+ y <- replicateM 15 $ readSource src
46+ S.concat y `shouldBe` "BLAH"
47+ it "chunk boundaries" $ do
48+ ref <- newIORef
49+ [ "5\r\n"
50+ , "12345\r\n3\r"
51+ , "\n678\r\n0\r\n"
52+ , "\r\nBLAH"
53+ ]
54+ src <- mkSource $ do
55+ x <- readIORef ref
56+ case x of
57+ [] -> return S.empty
58+ y:z -> do
59+ writeIORef ref z
60+ return y
61+ csrc <- mkCSource src
62+
63+ x <- replicateM 15 $ readCSource csrc
64+ S.concat x `shouldBe` "12345678"
65+
4566 y <- replicateM 15 $ readSource src
4667 S.concat y `shouldBe` "BLAH"
warp/warp.cabal+1−1
@@ -1,5 +1,5 @@
11Name: warp
2−Version: 3.0.0.1
2+Version: 3.0.0.2
33Synopsis: A fast, light-weight web server for WAI applications.
44License: MIT
55License-file: LICENSE