@@ -19,7 +19,7 @@ main = hspec spec
1919
2020testRange :: S.ByteString -- ^ range value
2121 -> String -- ^ expected output
22− -> String -- ^ expected content-range value
22+ -> Maybe String -- ^ expected content-range value
2323 -> Spec
2424testRange range out crange = it title $ withApp defaultSettings app $ \port -> do
2525 handle <- connectTo "127.0.0.1" $ PortNumber $ fromIntegral port
@@ -31,9 +31,9 @@ testRange range out crange = it title $ withApp defaultSettings app $ \port -> d
3131 threadDelay 10000
3232 bss <- fmap (lines . filter (/= '\r') . S8.unpack) $ S.hGetSome handle 1024
3333 hClose handle
34− out `shouldBe` last bss
34+ last bss `shouldBe` out
3535 let hs = mapMaybe toHeader bss
36− lookup "Content-Range" hs `shouldBe` Just ("bytes " ++ crange)
36+ lookup "Content-Range" hs `shouldBe` fmap ("bytes " ++) crange
3737 lookup "Content-Length" hs `shouldBe` Just (show $ length $ last bss)
3838 where
3939 app _ = ($ responseFile status200 [] "attic/hex" Nothing)
@@ -83,10 +83,12 @@ testFileRange desc s rsphdr file mPart mRange ans = it desc $ do
8383spec :: Spec
8484spec = do
8585 describe "range requests" $ do
86− testRange "2-3" "23" "2-3/16"
87− testRange "5-" "56789abcdef" "5-15/16"
88− testRange "5-8" "5678" "5-8/16"
89− testRange "-3" "def" "13-15/16"
86+ testRange "2-3" "23" $ Just "2-3/16"
87+ testRange "5-" "56789abcdef" $ Just "5-15/16"
88+ testRange "5-8" "5678" $ Just "5-8/16"
89+ testRange "-3" "def" $ Just "13-15/16"
90+ testRange "16-" "" $ Just "*/16"
91+ testRange "-17" "0123456789abcdef" Nothing
9092
9193 describe "partial files" $ do
9294 testPartial 16 2 2 "23"
@@ -114,6 +116,10 @@ spec = do
114116 "gets a file size from file system and handles Range and returns Partical Content"
115117 status200 [] "attic/hex" Nothing (Just "bytes=2-14")
116118 $ Right (status206,[("Content-Range","bytes 2-14/16"),("Content-Length","13")],2,13)
119+ testFileRange
120+ "truncates end point of range to file size"
121+ status200 [] "attic/hex" Nothing (Just "bytes=10-20")
122+ $ Right (status206,[("Content-Range","bytes 10-15/16"),("Content-Length","6")],10,6)
117123 testFileRange
118124 "gets a file size from file system and handles Range and returns OK if Range means the entire"
119125 status200 [] "attic/hex" Nothing (Just "bytes=0-15")