Skip to content

Commit

Permalink
Remove external port check in framwork
Browse files Browse the repository at this point in the history
  • Loading branch information
krrr committed Feb 25, 2016
1 parent 1124567 commit b7b033d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 34 deletions.
34 changes: 2 additions & 32 deletions wstan/autobahn/websocket/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2447,25 +2447,8 @@ 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
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))
else:
if self.debugCodePaths:
self.log.debug("skipping opening handshake port checking - neither WS URL nor external port set")

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:
if self.debugCodePaths:
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 @@ -2955,7 +2938,6 @@ def __init__(self,
protocols=None,
server="AutobahnPython/%s" % __version__,
headers=None,
externalPort=None,
debug=False,
debugCodePaths=False):
"""
Expand All @@ -2971,8 +2953,6 @@ def __init__(self,
:type server: str
:param headers: An optional mapping of additional HTTP headers to send during the WebSocket opening handshake.
:type headers: dict
:param externalPort: Optionally, the external visible port this factory will be reachable under (i.e. when running behind a L2/L3 forwarding device).
:type externalPort: int
:param debug: Debug mode (default: `False`).
:type debug: bool
:param debugCodePaths: Debug code paths mode (default: `False`).
Expand All @@ -2991,7 +2971,7 @@ def __init__(self,

# default WS session parameters
#
self.setSessionParameters(url, protocols, server, headers, externalPort)
self.setSessionParameters(url, protocols, server, headers)

# default WebSocket protocol options
#
Expand All @@ -3005,8 +2985,7 @@ def setSessionParameters(self,
url=None,
protocols=None,
server=None,
headers=None,
externalPort=None):
headers=None):
"""
Set WebSocket session parameters.
Expand All @@ -3020,8 +2999,6 @@ def setSessionParameters(self,
:type server: str
:param headers: An optional mapping of additional HTTP headers to send during the WebSocket opening handshake.
:type headers: dict
:param externalPort: Optionally, the external visible port this server will be reachable under (i.e. when running behind a L2/L3 forwarding device).
:type externalPort: int
"""
# parse WebSocket URI into components
(isSecure, host, port, resource, path, params) = parseWsUrl(url or "ws://localhost")
Expand All @@ -3039,13 +3016,6 @@ 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

def resetProtocolOptions(self):
"""
Reset all WebSocket protocol options to defaults.
Expand Down
2 changes: 0 additions & 2 deletions wstan/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ def main():
addr = config.tun_addr or config.uri_addr
port = config.tun_port or config.uri_port
uri = config.uri
if config.tun_port and config.tun_port != config.uri_port:
uri = uri.replace(':%d' % config.uri_port, ':%d' % config.tun_port)
factory = WebSocketServerFactory(uri)
factory.protocol = WSTunServerProtocol
factory.server = '' # hide Server field of handshake HTTP header
Expand Down

0 comments on commit b7b033d

Please sign in to comment.