@@ -42,7 +42,8 @@ module Network.Wai.Handler.WarpTLS (
4242#if __GLASGOW_HASKELL__ < 709
4343import Control.Applicative ((<$>))
4444#endif
45−import Control.Exception (Exception, throwIO, bracket, finally, handle, fromException, try, IOException, onException)
45+import Control.Exception (Exception, throwIO, bracket, finally, handle, fromException, try, IOException, onException, SomeException(..))
46+import qualified Control.Exception as E
4647import Control.Monad (void)
4748import qualified Crypto.Random.AESCtr
4849import qualified Data.ByteString as S
@@ -321,9 +322,11 @@ httpOverTls TLSSettings{..} s bs0 params = do
321322 backend recvN = TLS.Backend {
322323 TLS.backendFlush = return ()
323324 , TLS.backendClose = sClose s
324− , TLS.backendSend = sendAll s
325+ , TLS.backendSend = sendAll' s
325326 , TLS.backendRecv = recvN
326327 }
328+ sendAll' sock bs = sendAll sock bs `E.catch` \(SomeException _) ->
329+ throwIO ConnectionClosedByPeer
327330 conn ctx writeBuf ref = Connection {
328331 connSendMany = TLS.sendData ctx . L.fromChunks
329332 , connSendAll = sendall