warp 2.1.3.2 → 2.1.3.3
raw patch · 3 files changed
+34/−10 lines, 3 files
Files
- Network/Wai/Handler/Warp/Request.hs +5/−8
- test/RequestSpec.hs +28/−1
- warp.cabal +1/−1
Network/Wai/Handler/Warp/Request.hs view
@@ -165,11 +165,12 @@ close = throwIO IncompleteHeaders push :: THStatus -> ByteString -> Sink ByteString IO (Maybe ByteString, [ByteString])-push (THStatus len lines prepend) bs+push (THStatus len lines prepend) bs' -- Too many bytes | len > maxTotalHeaderLength = throwIO OverLargeHeader | otherwise = push' mnl where+ bs = prepend bs' bsLen = S.length bs mnl = do nl <- S.elemIndex 10 bs@@ -191,13 +192,13 @@ push' Nothing = await >>= maybe close (push status) where len' = len + bsLen- prepend' = prepend . S.append bs+ prepend' = S.append bs status = THStatus len' lines prepend' -- Found a newline, but next line continues as a multiline header push' (Just (end, True)) = push status rest where rest = S.drop (end + 1) bs- prepend' = prepend . S.append (SU.unsafeTake (checkCR bs end) bs)+ prepend' = S.append (SU.unsafeTake (checkCR bs end) bs) len' = len + end status = THStatus len' lines prepend' -- Found a newline at position end.@@ -222,11 +223,7 @@ await >>= maybe close (push status) where start = end + 1 -- start of next chunk- line- -- There were some bytes before the newline, get them- | end > 0 = prepend $ SU.unsafeTake (checkCR bs end) bs- -- No bytes before the newline- | otherwise = prepend S.empty+ line = SU.unsafeTake (checkCR bs end) bs {-# INLINE checkCR #-} checkCR :: ByteString -> Int -> Int
test/RequestSpec.hs view
@@ -5,12 +5,15 @@ module RequestSpec (main, spec) where import Data.Conduit-import Data.Conduit.List+import qualified Data.Conduit.Binary as CB+import Data.Conduit.List (sourceList) import Network.Wai.Handler.Warp.Request import Network.Wai.Handler.Warp.RequestHeader (parseByteRanges) import Network.Wai.Handler.Warp.Types import Test.Hspec+import Test.Hspec.QuickCheck import qualified Data.ByteString.Char8 as S8+import qualified Data.ByteString.Lazy as L import qualified Network.HTTP.Types.Header as HH deriving instance Show HH.ByteRange@@ -30,6 +33,30 @@ tooMany `shouldThrow` overLargeHeader it "throws OverLargeHeader when too large" $ tooLarge `shouldThrow` overLargeHeader+ it "known bad chunking behavior #239" $ do+ let chunks =+ [ "GET / HTTP/1.1\r\nConnection: Close\r"+ , "\n\r\n"+ ]+ (mleftover, actual) <- mapM_ yield chunks $$ headerLines+ mleftover `shouldBe` Nothing+ actual `shouldBe` ["GET / HTTP/1.1", "Connection: Close"]+ prop "random chunking" $ \breaks extraS -> do+ let bsFull = "GET / HTTP/1.1\r\nConnection: Close\r\n\r\n" `S8.append` extra+ extra = S8.pack extraS+ chunks = loop breaks bsFull+ loop [] bs = [bs, undefined]+ loop (x:xs) bs =+ bs1 : loop xs bs2+ where+ (bs1, bs2) = S8.splitAt ((x `mod` 10) + 1) bs+ (leftover, actual) <- mapM_ yield chunks $$ do+ (_, actual) <- headerLines+ x' <- CB.take (length extraS)+ let x = S8.concat $ L.toChunks x'+ return (x, actual)+ actual `shouldBe` ["GET / HTTP/1.1", "Connection: Close"]+ leftover `shouldBe` extra describe "parseByteRanges" $ do let test x y = it x $ parseByteRanges (S8.pack x) `shouldBe` y test "bytes=0-499" $ Just [HH.ByteRangeFromTo 0 499]
warp.cabal view
@@ -1,5 +1,5 @@ Name: warp-Version: 2.1.3.2+Version: 2.1.3.3 Synopsis: A fast, light-weight web server for WAI applications. License: MIT License-file: LICENSE