Skip to content

Commit

Permalink
Removed externalPort assignment when not set (#1378)
Browse files Browse the repository at this point in the history
* Removed externalPort assignment when not set
* Simplified external port check code

Co-authored-by: Pramodh KP <pramodh@rapyuta-robotics.com>
  • Loading branch information
pramodhkp and Pramodh KP committed May 12, 2020
1 parent 0e19838 commit 80fe02d
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions autobahn/websocket/protocol.py
Expand Up @@ -2615,7 +2615,7 @@ def processHandshake(self):
except ValueError:
return self.failHandshake("invalid port '%s' in HTTP Host header '%s'" % (str(p.strip()), str(self.http_request_host)))

# do port checking only if externalPort or URL was set
# do port checking only if externalPort was set
if self.factory.externalPort:
if port != self.factory.externalPort:
return self.failHandshake("port %d in HTTP Host header '%s' does not match server listening port %s" % (port, str(self.http_request_host), self.factory.externalPort))
Expand All @@ -2624,14 +2624,6 @@ def processHandshake(self):

self.http_request_host = h

else:
# do port checking only if externalPort or URL was set
if self.factory.externalPort:
if not ((self.factory.isSecure and self.factory.externalPort == 443) or (not self.factory.isSecure and self.factory.externalPort == 80)):
return self.failHandshake("missing port in HTTP Host header '%s' and server runs on non-standard port %d (wss = %s)" % (str(self.http_request_host), self.factory.externalPort, self.factory.isSecure))
else:
self.log.debug("skipping opening handshake port checking - neither WS URL nor external port set")

# Upgrade
#
if 'upgrade' not in self.http_headers:
Expand Down Expand Up @@ -3195,12 +3187,7 @@ def setSessionParameters(self,
self.server = server
self.headers = headers or {}

if externalPort:
self.externalPort = externalPort
elif url:
self.externalPort = self.port
else:
self.externalPort = None
self.externalPort = externalPort

def resetProtocolOptions(self):
"""
Expand Down

0 comments on commit 80fe02d

Please sign in to comment.