Skip to content

Commit

Permalink
move success return to try/else
Browse files Browse the repository at this point in the history
  • Loading branch information
toppk committed Sep 25, 2022
1 parent 6c98cef commit 5ede676
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cheroot/ssl/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,20 +272,21 @@ def bind(self, sock):

def wrap(self, sock):
"""Wrap and return the given socket, plus WSGI environ entries."""
EMPTY_RESULT = None, {}
try:
s = self.context.wrap_socket(
sock, do_handshake_on_connect=True, server_side=True,
)
return s, self.get_environ(s)
except ssl.SSLError as ex:
if ex.errno == ssl.SSL_ERROR_SSL:
if _assert_ssl_exc_contains(ex, 'http request'):
# The client is speaking HTTP to an HTTPS server.
raise errors.NoSSLError
except (generic_socket_error, ssl.SSLZeroReturnError):
except generic_socket_error:
pass
# empty result
return None, {}
else:
return s, self.get_environ(s)
return EMPTY_RESULT

def get_environ(self, sock):
"""Create WSGI environ entries to be merged into each request."""
Expand Down

0 comments on commit 5ede676

Please sign in to comment.