@@ -329,18 +329,31 @@ serveConnection conn ii addr isSecure' settings app = do
329329 -- If there is an unknown or large amount of data to still be read
330330 -- from the request body, simple drop this connection instead of
331331 -- reading it all in to satisfy a keep-alive request.
332− let maxToRead = 8192 -- FIXME too low?
333− tryKeepAlive = do
334− -- flush the rest of the request body
335− isComplete <- flushBody (requestBody req) maxToRead
336− when isComplete $ do
337− T.resume th
338− recvSendLoop istatus fromClient
339− case mremainingRef of
340− Just ref -> do
341− remaining <- readIORef ref
342− when (remaining <= maxToRead) tryKeepAlive
343− Nothing -> tryKeepAlive
332+ case settingsMaximumBodyFlush settings of
333+ Nothing -> do
334+ flushEntireBody (requestBody req)
335+ T.resume th
336+ recvSendLoop istatus fromClient
337+ Just maxToRead -> do
338+ let tryKeepAlive = do
339+ -- flush the rest of the request body
340+ isComplete <- flushBody (requestBody req) maxToRead
341+ when isComplete $ do
342+ T.resume th
343+ recvSendLoop istatus fromClient
344+ case mremainingRef of
345+ Just ref -> do
346+ remaining <- readIORef ref
347+ when (remaining <= maxToRead) tryKeepAlive
348+ Nothing -> tryKeepAlive
349+
350+flushEntireBody :: IO ByteString -> IO ()
351+flushEntireBody src =
352+ loop
353+ where
354+ loop = do
355+ bs <- src
356+ unless (S.null bs) loop
344357
345358flushBody :: IO ByteString -- ^ get next chunk
346359 -> Int -- ^ maximum to flush