on master help sign in
Lift up the isHead guard. (#468)

Note that content-Length: is not necessary in a response to HEAD.

commit0297412e7f745eaf5c480fbb914a041fb37c80d4 authorKazu Yamamoto <kazu@iij.ad.jp> dateTue 24 Nov 2015, 12:46 (11 years ago) parent0d7072c
2 files changed+22−27
warp/Network/Wai/Handler/Warp/Response.hs+20−25 warp/test/RunSpec.hs+2−2
warp/Network/Wai/Handler/Warp/Response.hs+20−25
@@ -180,14 +180,12 @@ sendResponse defServer conn ii req reqidxhdr src response = do
180180 isChunked = not isHead && isChunked0
181181 (isKeepAlive, needsChunked) = infoFromResponse rspidxhdr (isPersist,isChunked)
182182 isHead = requestMethod req == H.methodHead
183− rsp = case response of
184− ResponseFile _ _ path mPart -> RspFile path mPart mRange isHead (T.tickle th)
185− ResponseBuilder _ _ b
186− | isHead -> RspBuilder mempty False
187− | otherwise -> RspBuilder b needsChunked
188− ResponseStream _ _ fb
189− | isHead -> RspBuilder mempty False
190− | otherwise -> RspStream fb needsChunked th
183+ rsp
184+ | isHead = RspBuilder mempty False
185+ | otherwise = case response of
186+ ResponseFile _ _ path mPart -> RspFile path mPart mRange (T.tickle th)
187+ ResponseBuilder _ _ b -> RspBuilder b needsChunked
188+ ResponseStream _ _ fb -> RspStream fb needsChunked th
191189 ResponseRaw raw _ -> RspRaw raw src (T.tickle th)
192190 ret = case response of
193191 ResponseFile {} -> isPersist
@@ -222,7 +220,7 @@ sanitizeHeaderValue v = case S8.lines $ S.filter (/= _cr) v of
222220
223221----------------------------------------------------------------
224222
225−data Rsp = RspFile FilePath (Maybe FilePart) (Maybe HeaderValue) Bool (IO ())
223+data Rsp = RspFile FilePath (Maybe FilePart) (Maybe HeaderValue) (IO ())
226224 | RspBuilder Builder Bool
227225 | RspStream StreamingBody Bool T.Handle
228226 | RspRaw (IO ByteString -> (ByteString -> IO ()) -> IO ()) (IO ByteString) (IO ())
@@ -236,7 +234,7 @@ sendRsp :: Connection
236234 -> H.ResponseHeaders
237235 -> Rsp
238236 -> IO ()
239−sendRsp conn mfdc ver s0 hs0 (RspFile path mPart mRange isHead hook) = do
237+sendRsp conn mfdc ver s0 hs0 (RspFile path mPart mRange hook) = do
240238 ex <- fileRange s0 hs0 path mPart mRange
241239 case ex of
242240 Left _ex ->
@@ -245,24 +243,21 @@ sendRsp conn mfdc ver s0 hs0 (RspFile path mPart mRange isHead hook) = do
245243#endif
246244 sendRsp conn mfdc ver s2 hs2 (RspBuilder body True)
247245 Right (s, hs, beg, len)
248− | len >= 0 ->
249− if isHead then
250− sendRsp conn mfdc ver s hs (RspBuilder mempty False)
251− else do
252− lheader <- composeHeader ver s hs
246+ | len >= 0 -> do
247+ lheader <- composeHeader ver s hs
253248#ifdef WINDOWS
254− let fid = FileId path Nothing
255− hook' = hook
249+ let fid = FileId path Nothing
250+ hook' = hook
256251#else
257− (mfd, hook') <- case mfdc of
258− -- settingsFdCacheDuration is 0
259− Nothing -> return (Nothing, hook)
260− Just fdc -> do
261− (fd, fresher) <- F.getFd fdc path
262− return (Just fd, hook >> fresher)
263− let fid = FileId path mfd
252+ (mfd, hook') <- case mfdc of
253+ -- settingsFdCacheDuration is 0
254+ Nothing -> return (Nothing, hook)
255+ Just fdc -> do
256+ (fd, fresher) <- F.getFd fdc path
257+ return (Just fd, hook >> fresher)
258+ let fid = FileId path mfd
264259#endif
265− connSendFile conn fid beg len hook' [lheader]
260+ connSendFile conn fid beg len hook' [lheader]
266261 | otherwise ->
267262 sendRsp conn mfdc ver H.status416
268263 (filter (\(k, _) -> k /= "content-length") hs)
warp/test/RunSpec.hs+2−2
@@ -395,12 +395,12 @@ spec = do
395395 it "file, no range" $ withApp defaultSettings app $ \port -> do
396396 bs <- S.readFile fp
397397 res <- sendHEAD $ concat ["http://127.0.0.1:", show port, "/file"]
398− getHeaderValue HdrContentLength res `shouldBe` Just (show $ S.length bs)
398+ getHeaderValue HdrContentLength res `shouldBe` Nothing
399399 it "file, with range" $ withApp defaultSettings app $ \port -> do
400400 res <- sendHEADwH
401401 (concat ["http://127.0.0.1:", show port, "/file"])
402402 [mkHeader HdrRange "bytes=0-1"]
403− getHeaderValue HdrContentLength res `shouldBe` Just "2"
403+ getHeaderValue HdrContentLength res `shouldBe` Nothing
404404
405405consumeBody :: IO ByteString -> IO [ByteString]
406406consumeBody body =