@@ -1,18 +1,27 @@
1+{-# OPTIONS_GHC -fno-warn-orphans #-}
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE StandaloneDeriving #-}
3module RequestSpec (main, spec) where
5module RequestSpec (main, spec) where
5import Data.Conduit
7import Data.Conduit
6import Data.Conduit.List
8import Data.Conduit.List
7import Network.Wai.Handler.Warp.Request
9import Network.Wai.Handler.Warp.Request
10+import Network.Wai.Handler.Warp.RequestHeader (parseByteRanges)
8import Network.Wai.Handler.Warp.Types
11import Network.Wai.Handler.Warp.Types
9import Test.Hspec
12import Test.Hspec
13+import qualified Data.ByteString.Char8 as S8
14+import qualified Network.HTTP.Types.Header as HH
16+deriving instance Show HH.ByteRange
17+deriving instance Eq HH.ByteRange
11main :: IO ()
19main :: IO ()
12main = hspec spec
20main = hspec spec
14spec :: Spec
22spec :: Spec
15−spec = describe "headerLines" $ do
24+ describe "headerLines" $ do
16 it "takes until blank" $
25 it "takes until blank" $
17 blankSafe >>= (`shouldBe` ["foo", "bar", "baz"])
26 blankSafe >>= (`shouldBe` ["foo", "bar", "baz"])
18 it "ignored leading whitespace in bodies" $
27 it "ignored leading whitespace in bodies" $
@@ -21,6 +30,14 @@ spec = describe "headerLines" $ do
21 tooMany `shouldThrow` overLargeHeader
30 tooMany `shouldThrow` overLargeHeader
22 it "throws OverLargeHeader when too large" $
31 it "throws OverLargeHeader when too large" $
23 tooLarge `shouldThrow` overLargeHeader
32 tooLarge `shouldThrow` overLargeHeader
33+ describe "parseByteRanges" $ do
34+ let test x y = it x $ parseByteRanges (S8.pack x) `shouldBe` y
35+ test "bytes=0-499" $ Just [HH.ByteRangeFromTo 0 499]
36+ test "bytes=500-999" $ Just [HH.ByteRangeFromTo 500 999]
37+ test "bytes=-500" $ Just [HH.ByteRangeSuffix 500]
38+ test "bytes=9500-" $ Just [HH.ByteRangeFrom 9500]
39+ test "foobytes=9500-" Nothing
40+ test "bytes=0-0,-1" $ Just [HH.ByteRangeFromTo 0 0, HH.ByteRangeSuffix 1]
25 blankSafe = (sourceList ["f", "oo\n", "bar\nbaz\n\r\n"]) $$ headerLines
42 blankSafe = (sourceList ["f", "oo\n", "bar\nbaz\n\r\n"]) $$ headerLines
26 whiteSafe = (sourceList ["foo\r\nbar\r\nbaz\r\n\r\n hi there"]) $$ headerLines
43 whiteSafe = (sourceList ["foo\r\nbar\r\nbaz\r\n\r\n hi there"]) $$ headerLines