on master help sign in
HEAD file tests
commitcb1e8d9ba8bfa3c04dbc19ddaef9a66f87748227 authorMichael Snoyman <michael@snoyman.com> dateMon 23 Nov 2015, 07:40 (11 years ago) parentcbbeb23
2 files changed+16−2
warp/test/HTTP.hs+7−2 warp/test/RunSpec.hs+9
warp/test/HTTP.hs+7−2
@@ -2,13 +2,15 @@
22{-# OPTIONS_GHC -fno-warn-orphans #-}
33module HTTP (
44 sendGET
5− , sendHEAD
65 , sendGETwH
6+ , sendHEAD
7+ , sendHEADwH
78 , rspBody
89 , rspCode
910 , rspHeaders
1011 , getHeaderValue
1112 , HeaderName(..)
13+ , mkHeader
1214 ) where
1315
1416import Network.HTTP
@@ -21,7 +23,10 @@ sendGETwH :: String -> [Header] -> IO (Response String)
2123sendGETwH url hdr = unResult $ simpleHTTP $ (getRequest url) { rqHeaders = hdr }
2224
2325sendHEAD :: String -> IO (Response String)
24−sendHEAD url = unResult $ simpleHTTP $ headRequest url
26+sendHEAD url = sendHEADwH url []
27+
28+sendHEADwH :: String -> [Header] -> IO (Response String)
29+sendHEADwH url hdr = unResult $ simpleHTTP $ (headRequest url) { rqHeaders = hdr }
2530
2631unResult :: IO (Result (Response String)) -> IO (Response String)
2732unResult action = do
warp/test/RunSpec.hs+9
@@ -392,6 +392,15 @@ spec = do
392392 it "streaming" $ withApp defaultSettings app $ \port -> do
393393 res <- sendHEAD $ concat ["http://127.0.0.1:", show port, "/streaming"]
394394 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"
395404
396405consumeBody :: IO ByteString -> IO [ByteString]
397406consumeBody body =