on master help sign in
hasBody now checks if method is HEAD. (#468)
commit22450c7b00b66d3093a882b2dc2c03a5b9028a3e authorKazu Yamamoto <kazu@iij.ad.jp> dateFri 27 Nov 2015, 12:42 (11 years ago) parenta1c5e66
1 file changed+9−15
warp/Network/Wai/Handler/Warp/Response.hs+9−15
warp/Network/Wai/Handler/Warp/Response.hs+9−15
@@ -153,11 +153,7 @@ sendResponse :: ByteString -- ^ default server value
153153 -> IO Bool -- ^ Returing True if the connection is persistent.
154154sendResponse defServer conn ii req reqidxhdr src response = do
155155 hs <- addServerAndDate hs0
156− if hasBody s then do
157− -- HEAD comes here even if it does not have body. We include HEAD
158− -- responses here so that we generate appropriate content-length
159− -- headers below.
160− --
156+ if hasBody req s then do
161157 -- See definition of rsp below for proper body stripping.
162158 sendRsp conn mfdc ver s hs rsp
163159 T.tickle th
@@ -176,13 +172,9 @@ sendResponse defServer conn ii req reqidxhdr src response = do
176172 mfdc = fdCacher ii
177173 addServerAndDate = addDate dc rspidxhdr . addServer defServer rspidxhdr
178174 mRange = reqidxhdr ! idxRange
179− (isPersist,isChunked0) = infoFromRequest req reqidxhdr
180− isChunked = not isHead && isChunked0
175+ (isPersist,isChunked) = infoFromRequest req reqidxhdr
181176 (isKeepAlive, needsChunked) = infoFromResponse rspidxhdr (isPersist,isChunked)
182− isHead = requestMethod req == H.methodHead
183− rsp
184− | isHead = RspBuilder mempty False
185− | otherwise = case response of
177+ rsp = case response of
186178 ResponseFile _ _ path mPart -> RspFile path mPart mRange (T.tickle th)
187179 ResponseBuilder _ _ b -> RspBuilder b needsChunked
188180 ResponseStream _ _ fb -> RspStream fb needsChunked th
@@ -377,12 +369,14 @@ infoFromResponse rspidxhdr (isPersist,isChunked) = (isKeepAlive, needsChunked)
377369
378370----------------------------------------------------------------
379371
380−hasBody :: H.Status -> Bool
381−hasBody s = sc /= 204
382− && sc /= 304
383− && sc >= 200
372+hasBody :: Request -> H.Status -> Bool
373+hasBody req s = not isHead
374+ && sc /= 204
375+ && sc /= 304
376+ && sc >= 200
384377 where
385378 sc = H.statusCode s
379+ isHead = requestMethod req == H.methodHead
386380
387381----------------------------------------------------------------
388382