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

This reverts commit 0297412e7f745eaf5c480fbb914a041fb37c80d4.

commita364c54bf57688e259658f0e314498e595911ed5 authorKazu Yamamoto <kazu@iij.ad.jp> dateTue 1 Dec 2015, 16:38 (11 years ago) parent11906b2
2 files changed+27−22
warp/Network/Wai/Handler/Warp/Response.hs+25−20 warp/test/RunSpec.hs+2−2
warp/Network/Wai/Handler/Warp/Response.hs+25−20
@@ -186,12 +186,14 @@ sendResponse defServer conn ii req reqidxhdr src response = do
186186 isChunked = not isHead && isChunked0
187187 (isKeepAlive, needsChunked) = infoFromResponse rspidxhdr (isPersist,isChunked)
188188 isHead = requestMethod req == H.methodHead
189− rsp
190− | isHead = RspBuilder mempty False
191− | otherwise = case response of
192− ResponseFile _ _ path mPart -> RspFile path mPart mRange (T.tickle th)
193− ResponseBuilder _ _ b -> RspBuilder b needsChunked
194− ResponseStream _ _ fb -> RspStream fb needsChunked th
189+ rsp = case response of
190+ ResponseFile _ _ path mPart -> RspFile path mPart mRange isHead (T.tickle th)
191+ ResponseBuilder _ _ b
192+ | isHead -> RspBuilder mempty False
193+ | otherwise -> RspBuilder b needsChunked
194+ ResponseStream _ _ fb
195+ | isHead -> RspBuilder mempty False
196+ | otherwise -> RspStream fb needsChunked th
195197 ResponseRaw raw _ -> RspRaw raw src (T.tickle th)
196198 ret = case response of
197199 ResponseFile {} -> isPersist
@@ -226,7 +228,7 @@ sanitizeHeaderValue v = case S8.lines $ S.filter (/= _cr) v of
226228
227229----------------------------------------------------------------
228230
229−data Rsp = RspFile FilePath (Maybe FilePart) (Maybe HeaderValue) (IO ())
231+data Rsp = RspFile FilePath (Maybe FilePart) (Maybe HeaderValue) Bool (IO ())
230232 | RspBuilder Builder Bool
231233 | RspStream StreamingBody Bool T.Handle
232234 | RspRaw (IO ByteString -> (ByteString -> IO ()) -> IO ()) (IO ByteString) (IO ())
@@ -240,7 +242,7 @@ sendRsp :: Connection
240242 -> H.ResponseHeaders
241243 -> Rsp
242244 -> IO ()
243−sendRsp conn ii ver s0 hs0 (RspFile path mPart mRange hook) = do
245+sendRsp conn ii ver s0 hs0 (RspFile path mPart mRange isHead hook) = do
244246 ex <- fileRange s0 hs0 path mPart mRange get
245247 case ex of
246248 Left _ex ->
@@ -249,21 +251,24 @@ sendRsp conn ii ver s0 hs0 (RspFile path mPart mRange hook) = do
249251#endif
250252 sendRsp conn ii ver s2 hs2 (RspBuilder body True)
251253 Right (s, hs, beg, len)
252− | len >= 0 -> do
253− lheader <- composeHeader ver s hs
254+ | len >= 0 ->
255+ if isHead then
256+ sendRsp conn ii ver s hs (RspBuilder mempty False)
257+ else do
258+ lheader <- composeHeader ver s hs
254259#ifdef WINDOWS
255− let fid = FileId path Nothing
256− hook' = hook
260+ let fid = FileId path Nothing
261+ hook' = hook
257262#else
258− (mfd, hook') <- case mfdc of
259− -- settingsFdCacheDuration is 0
260− Nothing -> return (Nothing, hook)
261− Just fdc -> do
262− (fd, fresher) <- F.getFd fdc path
263− return (Just fd, hook >> fresher)
264− let fid = FileId path mfd
263+ (mfd, hook') <- case mfdc of
264+ -- settingsFdCacheDuration is 0
265+ Nothing -> return (Nothing, hook)
266+ Just fdc -> do
267+ (fd, fresher) <- F.getFd fdc path
268+ return (Just fd, hook >> fresher)
269+ let fid = FileId path mfd
265270#endif
266− connSendFile conn fid beg len hook' [lheader]
271+ connSendFile conn fid beg len hook' [lheader]
267272 | otherwise ->
268273 sendRsp conn ii ver H.status416
269274 (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` Nothing
398+ getHeaderValue HdrContentLength res `shouldBe` Just (show $ S.length bs)
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` Nothing
403+ getHeaderValue HdrContentLength res `shouldBe` Just "2"
404404
405405consumeBody :: IO ByteString -> IO [ByteString]
406406consumeBody body =