on master help sign in
Merge branch 'issue_640' of https://github.com/osa1/wai
9408c7fMichael Snoyman
warp-tls/Network/Wai/Handler/WarpTLS.hs+11−3
@@ -43,9 +43,9 @@ module Network.Wai.Handler.WarpTLS (
43 ) where
43 ) where
44
44
45import Control.Applicative ((<|>))
45import Control.Applicative ((<|>))
46−import Control.Exception (Exception, throwIO, bracket, finally, handle, fromException, try, IOException, onException, SomeException(..))
46+import Control.Exception (Exception, throwIO, bracket, finally, handle, fromException, try, IOException, onException, SomeException(..), handleJust)
47import qualified Control.Exception as E
47import qualified Control.Exception as E
48−import Control.Monad (void)
48+import Control.Monad (void, guard)
49import qualified Data.ByteString as S
49import qualified Data.ByteString as S
50import qualified Data.ByteString.Lazy as L
50import qualified Data.ByteString.Lazy as L
51import Data.Default.Class (def)
51import Data.Default.Class (def)
@@ -344,9 +344,17 @@ httpOverTls TLSSettings{..} s bs0 params = do
344 sendfile fid offset len hook headers =
344 sendfile fid offset len hook headers =
345 readSendFile writeBuf bufferSize sendall fid offset len hook headers
345 readSendFile writeBuf bufferSize sendall fid offset len hook headers
346
346
347− close' = void (tryIO $ TLS.bye ctx) `finally`
347+ close' = void (tryIO sendBye) `finally`
348 TLS.contextClose ctx
348 TLS.contextClose ctx
349
349
350+ sendBye =
351+ -- It's fine if the connection was closed by the other side before
352+ -- receiving close_notify, see RFC 5246 section 7.2.1.
353+ handleJust
354+ (\e -> guard (e == ConnectionClosedByPeer) >> return e)
355+ (const (return ()))
356+ (TLS.bye ctx)
357+
350 -- TLS version of recv with a cache for leftover input data.
358 -- TLS version of recv with a cache for leftover input data.
351 -- The cache is shared with recvBuf.
359 -- The cache is shared with recvBuf.
352 recv cref = do
360 recv cref = do