@@ -154,7 +154,11 @@ sendResponse :: ByteString -- ^ default server value
154154sendResponse defServer conn ii req reqidxhdr src response = do
155155 hs <- addServerAndDate hs0
156156 if hasBody s then do
157− -- HEAD comes here even if it does not have body.
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+ --
161+ -- See definition of rsp below for proper body stripping.
158162 sendRsp conn mfdc ver s hs rsp
159163 T.tickle th
160164 return ret
@@ -176,8 +180,10 @@ sendResponse defServer conn ii req reqidxhdr src response = do
176180 isChunked = not isHead && isChunked0
177181 (isKeepAlive, needsChunked) = infoFromResponse rspidxhdr (isPersist,isChunked)
178182 isHead = requestMethod req == H.methodHead
179− rsp = case response of
180− ResponseFile _ _ path mPart -> RspFile path mPart mRange isHead (T.tickle th)
183+ rsp
184+ | isHead = RspBuilder mempty False
185+ | otherwise = case response of
186+ ResponseFile _ _ path mPart -> RspFile path mPart mRange (T.tickle th)
181187 ResponseBuilder _ _ b -> RspBuilder b needsChunked
182188 ResponseStream _ _ fb -> RspStream fb needsChunked th
183189 ResponseRaw raw _ -> RspRaw raw src (T.tickle th)
@@ -214,7 +220,7 @@ sanitizeHeaderValue v = case S8.lines $ S.filter (/= _cr) v of
214220
215221----------------------------------------------------------------
216222
217−data Rsp = RspFile FilePath (Maybe FilePart) (Maybe HeaderValue) Bool (IO ())
223+data Rsp = RspFile FilePath (Maybe FilePart) (Maybe HeaderValue) (IO ())
218224 | RspBuilder Builder Bool
219225 | RspStream StreamingBody Bool T.Handle
220226 | RspRaw (IO ByteString -> (ByteString -> IO ()) -> IO ()) (IO ByteString) (IO ())
@@ -228,7 +234,7 @@ sendRsp :: Connection
228234 -> H.ResponseHeaders
229235 -> Rsp
230236 -> IO ()
231−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
232238 ex <- fileRange s0 hs0 path mPart mRange
233239 case ex of
234240 Left _ex ->
@@ -237,24 +243,21 @@ sendRsp conn mfdc ver s0 hs0 (RspFile path mPart mRange isHead hook) = do
237243#endif
238244 sendRsp conn mfdc ver s2 hs2 (RspBuilder body True)
239245 Right (s, hs, beg, len)
240− | len >= 0 ->
241− if isHead then
242− sendRsp conn mfdc ver s hs (RspBuilder mempty False)
243− else do
244− lheader <- composeHeader ver s hs
246+ | len >= 0 -> do
247+ lheader <- composeHeader ver s hs
245248#ifdef WINDOWS
246− let fid = FileId path Nothing
247− hook' = hook
249+ let fid = FileId path Nothing
250+ hook' = hook
248251#else
249− (mfd, hook') <- case mfdc of
250− -- settingsFdCacheDuration is 0
251− Nothing -> return (Nothing, hook)
252− Just fdc -> do
253− (fd, fresher) <- F.getFd fdc path
254− return (Just fd, hook >> fresher)
255− 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
256259#endif
257− connSendFile conn fid beg len hook' [lheader]
260+ connSendFile conn fid beg len hook' [lheader]
258261 | otherwise ->
259262 sendRsp conn mfdc ver H.status416
260263 (filter (\(k, _) -> k /= "content-length") hs)