Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanly close connection when client closes connection prematurely #844

Merged
merged 1 commit into from
May 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions warp-tls/Network/Wai/Handler/WarpTLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,12 @@ getter tlsset set sock params = do
return (mkConn tlsset set s params, sa)

mkConn :: TLS.TLSParams params => TLSSettings -> Settings -> Socket -> params -> IO (Connection, Transport)
mkConn tlsset set s params = switch `onException` close s
mkConn tlsset set s params = (safeRecv s 4096 >>= switch) `onException` close s
where
switch = do
firstBS <- safeRecv s 4096
if not (S.null firstBS) && S.head firstBS == 0x16 then
httpOverTls tlsset set s firstBS params
else
plainHTTP tlsset set s firstBS
switch firstBS
| S.null firstBS = close s >> throwIO ClientClosedConnectionPrematurely
| S.head firstBS == 0x16 = httpOverTls tlsset set s firstBS params
| otherwise = plainHTTP tlsset set s firstBS

----------------------------------------------------------------

Expand Down Expand Up @@ -590,6 +588,8 @@ recvPlain ref fallback = do

----------------------------------------------------------------

data WarpTLSException = InsecureConnectionDenied
data WarpTLSException
= InsecureConnectionDenied
| ClientClosedConnectionPrematurely
deriving (Show, Typeable)
instance Exception WarpTLSException