Skip to content

Commit

Permalink
Merge PR #844
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed May 19, 2021
2 parents def53be + 1849ee3 commit d7f6454
Showing 1 changed file with 8 additions and 8 deletions.
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

0 comments on commit d7f6454

Please sign in to comment.