on master help sign in
Revert "hasBody now checks if method is HEAD. (#468)"

This reverts commit 22450c7b00b66d3093a882b2dc2c03a5b9028a3e.

commit11906b21bd061b5c1acb99e2cd43088c0e066129 authorKazu Yamamoto <kazu@iij.ad.jp> dateTue 1 Dec 2015, 16:31 (11 years ago) parentaad53f1
1 file changed+15−9
warp/Network/Wai/Handler/Warp/Response.hs+15−9
warp/Network/Wai/Handler/Warp/Response.hs+15−9
@@ -160,7 +160,11 @@ sendResponse :: ByteString -- ^ default server value
160160 -> IO Bool -- ^ Returing True if the connection is persistent.
161161sendResponse defServer conn ii req reqidxhdr src response = do
162162 hs <- addServerAndDate hs0
163− if hasBody req s then do
163+ if hasBody s then do
164+ -- HEAD comes here even if it does not have body. We include HEAD
165+ -- responses here so that we generate appropriate content-length
166+ -- headers below.
167+ --
164168 -- See definition of rsp below for proper body stripping.
165169 sendRsp conn ii ver s hs rsp
166170 T.tickle th
@@ -178,9 +182,13 @@ sendResponse defServer conn ii req reqidxhdr src response = do
178182 dc = dateCacher ii
179183 addServerAndDate = addDate dc rspidxhdr . addServer defServer rspidxhdr
180184 mRange = reqidxhdr ! idxRange
181− (isPersist,isChunked) = infoFromRequest req reqidxhdr
185+ (isPersist,isChunked0) = infoFromRequest req reqidxhdr
186+ isChunked = not isHead && isChunked0
182187 (isKeepAlive, needsChunked) = infoFromResponse rspidxhdr (isPersist,isChunked)
183− rsp = case response of
188+ isHead = requestMethod req == H.methodHead
189+ rsp
190+ | isHead = RspBuilder mempty False
191+ | otherwise = case response of
184192 ResponseFile _ _ path mPart -> RspFile path mPart mRange (T.tickle th)
185193 ResponseBuilder _ _ b -> RspBuilder b needsChunked
186194 ResponseStream _ _ fb -> RspStream fb needsChunked th
@@ -377,14 +385,12 @@ infoFromResponse rspidxhdr (isPersist,isChunked) = (isKeepAlive, needsChunked)
377385
378386----------------------------------------------------------------
379387
380−hasBody :: Request -> H.Status -> Bool
381−hasBody req s = not isHead
382− && sc /= 204
383− && sc /= 304
384− && sc >= 200
388+hasBody :: H.Status -> Bool
389+hasBody s = sc /= 204
390+ && sc /= 304
391+ && sc >= 200
385392 where
386393 sc = H.statusCode s
387− isHead = requestMethod req == H.methodHead
388394
389395----------------------------------------------------------------
390396