@@ -1,18 +1,27 @@
1+{-# OPTIONS_GHC -fno-warn-orphans #-}
12{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE StandaloneDeriving #-}
24
35module RequestSpec (main, spec) where
46
57import Data.Conduit
68import Data.Conduit.List
79import Network.Wai.Handler.Warp.Request
10+import Network.Wai.Handler.Warp.RequestHeader (parseByteRanges)
811import Network.Wai.Handler.Warp.Types
912import Test.Hspec
13+import qualified Data.ByteString.Char8 as S8
14+import qualified Network.HTTP.Types.Header as HH
15+
16+deriving instance Show HH.ByteRange
17+deriving instance Eq HH.ByteRange
1018
1119main :: IO ()
1220main = hspec spec
1321
1422spec :: Spec
15−spec = describe "headerLines" $ do
23+spec = do
24+ describe "headerLines" $ do
1625 it "takes until blank" $
1726 blankSafe >>= (`shouldBe` ["foo", "bar", "baz"])
1827 it "ignored leading whitespace in bodies" $
@@ -21,6 +30,14 @@ spec = describe "headerLines" $ do
2130 tooMany `shouldThrow` overLargeHeader
2231 it "throws OverLargeHeader when too large" $
2332 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]
2441 where
2542 blankSafe = (sourceList ["f", "oo\n", "bar\nbaz\n\r\n"]) $$ headerLines
2643 whiteSafe = (sourceList ["foo\r\nbar\r\nbaz\r\n\r\n hi there"]) $$ headerLines