@@ -525,15 +525,15 @@ sendResponse th req conn r = sendResponse' r
525525 return $ addClToHeaders cl
526526 connSendMany conn $ L.toChunks $ toLazyByteString $
527527 headers version s lengthyHeaders False
528−
529528 T.tickle th
530−
531− if not (hasBody s req) then return isPersist else do
529+ if hasBody s req then do
532530 case mpart of
533531 Nothing -> connSendFile conn fp 0 cl (T.tickle th)
534532 Just part -> connSendFile conn fp (filePartOffset part) (filePartByteCount part) (T.tickle th)
535533 T.tickle th
536534 return isPersist
535+ else
536+ return isPersist
537537 where
538538 addClToHeaders cl = (("Content-Length", B.pack $ show cl):hs, fromIntegral cl)
539539
@@ -559,8 +559,18 @@ sendResponse th req conn r = sendResponse' r
559559 `mappend` chunkedTransferTerminator
560560 else headers' False `mappend` b
561561
562− sendResponse' (ResponseSource s hs bodyFlush) =
563− response
562+ sendResponse' (ResponseSource s hs bodyFlush)
563+ | hasBody s req = do
564+ let src = CL.sourceList [headers' needsChunked'] `mappend`
565+ (if needsChunked' then body C.$= chunk else body)
566+ src C.$$ builderToByteString C.=$ connSink conn th
567+ return $ isKeepAlive hs
568+ | otherwise = liftIO $ do
569+ connSendMany conn
570+ $ L.toChunks $ toLazyByteString
571+ $ headers' False
572+ T.tickle th
573+ return isPersist
564574 where
565575 body = fmap (\x -> case x of
566576 C.Flush -> flush
@@ -568,26 +578,12 @@ sendResponse th req conn r = sendResponse' r
568578 headers' = headers version s hs
569579 -- FIXME perhaps alloca a buffer per thread and reuse that in all
570580 -- functions below. Should lessen greatly the GC burden (I hope)
571− response
572− | not (hasBody s req) = liftIO $ do
573− connSendMany conn
574− $ L.toChunks $ toLazyByteString
575− $ headers' False
576− T.tickle th
577− return (checkPersist req)
578− | otherwise = do
579− let src =
580− CL.sourceList [headers' needsChunked'] `mappend`
581− (if needsChunked' then body C.$= chunk else body)
582− src C.$$ builderToByteString C.=$ connSink conn th
583− return $ isKeepAlive hs
584581 needsChunked' = needsChunked hs
585582 chunk :: C.Conduit Builder IO Builder
586583 chunk = C.Conduit
587584 { C.conduitPush = push
588585 , C.conduitClose = close
589586 }
590−
591587 conduit = C.Conduit push close
592588 push x = return $ C.Producing conduit [chunkedTransferEncoding x]
593589 close = return [chunkedTransferTerminator]