@@ -59,6 +59,33 @@ spec = do
5959 test "bytes=9500-" $ Just [HH.ByteRangeFrom 9500]
6060 test "foobytes=9500-" Nothing
6161 test "bytes=0-0,-1" $ Just [HH.ByteRangeFromTo 0 0, HH.ByteRangeSuffix 1]
62+
63+ describe "headerLines" $ do
64+ it "can handle a nomarl case" $ do
65+ src <- mkSourceFunc ["Status: 200\r\nContent-Type: text/plain\r\n\r\n"] >>= mkSource
66+ x <- headerLines src
67+ x `shouldBe` ["Status: 200", "Content-Type: text/plain"]
68+
69+ it "can handle a nasty case (1)" $ do
70+ src <- mkSourceFunc ["Status: 200", "\r\nContent-Type: text/plain", "\r\n\r\n"] >>= mkSource
71+ x <- headerLines src
72+ x `shouldBe` ["Status: 200", "Content-Type: text/plain"]
73+
74+ it "can handle a nasty case (1)" $ do
75+ src <- mkSourceFunc ["Status: 200", "\r", "\nContent-Type: text/plain", "\r", "\n\r\n"] >>= mkSource
76+ x <- headerLines src
77+ x `shouldBe` ["Status: 200", "Content-Type: text/plain"]
78+
79+ it "can handle a nasty case (1)" $ do
80+ src <- mkSourceFunc ["Status: 200", "\r", "\n", "Content-Type: text/plain", "\r", "\n", "\r", "\n"] >>= mkSource
81+ x <- headerLines src
82+ x `shouldBe` ["Status: 200", "Content-Type: text/plain"]
83+
84+ it "can handle an illegal case (1)" $ do
85+ src <- mkSourceFunc ["\nStatus:", "\n 200", "\nContent-Type: text/plain", "\r\n\r\n"] >>= mkSource
86+ x <- headerLines src
87+ x `shouldBe` ["Status: 200", "Content-Type: text/plain"]
88+
6289 where
6390 blankSafe = headerLinesList ["f", "oo\n", "bar\nbaz\n\r\n"]
6491 whiteSafe = headerLinesList ["foo\r\nbar\r\nbaz\r\n\r\n hi there"]
@@ -101,3 +128,16 @@ consumeLen len0 src =
101128
102129overLargeHeader :: Selector InvalidRequest
103130overLargeHeader e = e == OverLargeHeader
131+
132+mkSourceFunc :: [S8.ByteString] -> IO (IO S8.ByteString)
133+mkSourceFunc bss = do
134+ ref <- newIORef bss
135+ return $ reader ref
136+ where
137+ reader ref = do
138+ xss <- readIORef ref
139+ case xss of
140+ [] -> return S.empty
141+ (x:xs) -> do
142+ writeIORef ref xs
143+ return x