@@ -36,7 +36,7 @@ import Network.Wai (Application)
3636import Network.Socket (Socket, sClose, withSocketsDo, SockAddr, accept)
3737import qualified Data.ByteString as S
3838import qualified Data.ByteString.Lazy as L
39−import Control.Exception (bracket, finally, handle, fromException, try, IOException)
39+import Control.Exception (bracket, finally, handle, fromException, try, IOException, onException)
4040import qualified Network.TLS.Extra as TLSExtra
4141import qualified Data.ByteString as B
4242import Data.Streaming.Network (bindPortTCP, safeRecv)
@@ -257,10 +257,10 @@ mkConn :: TLS.TLSParams params => TLSSettings -> Socket -> params -> IO (Connect
257257mkConn tlsset s params = do
258258 firstBS <- safeRecv s 4096
259259 cachedRef <- I.newIORef firstBS
260− if not (B.null firstBS) && B.head firstBS == 0x16 then
260+ (if not (B.null firstBS) && B.head firstBS == 0x16 then
261261 httpOverTls tlsset s cachedRef params
262262 else
263− plainHTTP tlsset s cachedRef
263+ plainHTTP tlsset s cachedRef) `onException` sClose s
264264
265265----------------------------------------------------------------
266266