on master help sign in
HEAD file tests
cb1e8d9Michael Snoyman
warp/test/HTTP.hs+7−2
@@ -2,13 +2,15 @@
2{-# OPTIONS_GHC -fno-warn-orphans #-}
2{-# OPTIONS_GHC -fno-warn-orphans #-}
3module HTTP (
3module HTTP (
4 sendGET
4 sendGET
5− , sendHEAD
6 , sendGETwH
5 , sendGETwH
6+ , sendHEAD
7+ , sendHEADwH
7 , rspBody
8 , rspBody
8 , rspCode
9 , rspCode
9 , rspHeaders
10 , rspHeaders
10 , getHeaderValue
11 , getHeaderValue
11 , HeaderName(..)
12 , HeaderName(..)
13+ , mkHeader
12 ) where
14 ) where
13
15
14import Network.HTTP
16import Network.HTTP
@@ -21,7 +23,10 @@ sendGETwH :: String -> [Header] -> IO (Response String)
21sendGETwH url hdr = unResult $ simpleHTTP $ (getRequest url) { rqHeaders = hdr }
23sendGETwH url hdr = unResult $ simpleHTTP $ (getRequest url) { rqHeaders = hdr }
22
24
23sendHEAD :: String -> IO (Response String)
25sendHEAD :: String -> IO (Response String)
26+sendHEAD url = sendHEADwH url []
27+
28+sendHEADwH :: String -> [Header] -> IO (Response String)
24−sendHEAD url = unResult $ simpleHTTP $ headRequest url
29+sendHEADwH url hdr = unResult $ simpleHTTP $ (headRequest url) { rqHeaders = hdr }
25
30
26unResult :: IO (Result (Response String)) -> IO (Response String)
31unResult :: IO (Result (Response String)) -> IO (Response String)
27unResult action = do
32unResult action = do
warp/test/RunSpec.hs+9
@@ -392,6 +392,15 @@ spec = do
392 it "streaming" $ withApp defaultSettings app $ \port -> do
392 it "streaming" $ withApp defaultSettings app $ \port -> do
393 res <- sendHEAD $ concat ["http://127.0.0.1:", show port, "/streaming"]
393 res <- sendHEAD $ concat ["http://127.0.0.1:", show port, "/streaming"]
394 rspBody res `shouldBe` ""
394 rspBody res `shouldBe` ""
395+ it "file, no range" $ withApp defaultSettings app $ \port -> do
396+ bs <- S.readFile fp
397+ res <- sendHEAD $ concat ["http://127.0.0.1:", show port, "/file"]
398+ getHeaderValue HdrContentLength res `shouldBe` Just (show $ S.length bs)
399+ it "file, with range" $ withApp defaultSettings app $ \port -> do
400+ res <- sendHEADwH
401+ (concat ["http://127.0.0.1:", show port, "/file"])
402+ [mkHeader HdrRange "bytes=0-1"]
403+ getHeaderValue HdrContentLength res `shouldBe` Just "2"
395
404
396consumeBody :: IO ByteString -> IO [ByteString]
405consumeBody :: IO ByteString -> IO [ByteString]
397consumeBody body =
406consumeBody body =