@@ -18,6 +18,7 @@ import Network (sClose, Socket)
1818import Network.Socket (accept, SockAddr)
1919import qualified Network.Socket.ByteString as Sock
2020import Network.Wai
21+import Network.Wai.Internal (ResponseReceived (ResponseReceived))
2122import qualified Network.Wai.Handler.Warp.Date as D
2223import qualified Network.Wai.Handler.Warp.FdCache as F
2324import Network.Wai.Handler.Warp.Buffer
@@ -255,13 +256,17 @@ serveConnection conn ii addr isSecure' settings app = do
255256 -- In the event that some scarce resource was acquired during
256257 -- creating the request, we need to make sure that we don't get
257258 -- an async exception before calling the ResponseSource.
258− keepAlive <- app req $ \res -> do
259+ keepAliveRef <- newIORef $ error "keepAliveRef not filled"
260+ _ <- app req $ \res -> do
259261 T.resume th
260262 -- FIXME consider forcing evaluation of the res here to
261263 -- send more meaningful error messages to the user.
262264 -- However, it may affect performance.
263265 writeIORef istatus False
264− sendResponse conn ii req idxhdr (readSource fromClient) res
266+ keepAlive <- sendResponse conn ii req idxhdr (readSource fromClient) res
267+ writeIORef keepAliveRef keepAlive
268+ return ResponseReceived
269+ keepAlive <- readIORef keepAliveRef
265270
266271 -- We just send a Response and it takes a time to
267272 -- receive a Request again. If we immediately call recv,