Skip to content
Closed
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions ws4py/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
__all__ = ['WebSocketBaseClient']

class WebSocketBaseClient(WebSocket):
def __init__(self, url, protocols, extensions):
def __init__(self, url, protocols, extensions, custom_headers=[]):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
WebSocket.__init__(self, sock, protocols=protocols, extensions=extensions)
self.stream.always_mask = True
self.stream.expect_masking = False
self.key = b64encode(os.urandom(16))
self.url = url
self.custom_headers = custom_headers

def close(self, code=1000, reason=''):
if not self.client_terminated:
Expand Down Expand Up @@ -77,8 +78,8 @@ def handshake_headers(self):
host = parts.netloc
if ':' in host:
host, port = parts.netloc.split(':')
headers = [

headers = self.custom_headers + [
('Host', host),
('Connection', 'Upgrade'),
('Upgrade', 'websocket'),
Expand Down
6 changes: 3 additions & 3 deletions ws4py/client/tornadoclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
__all__ = ['TornadoWebSocketClient']

class TornadoWebSocketClient(WebSocketBaseClient):
def __init__(self, url, protocols=None, extensions=None, io_loop=None):
WebSocketBaseClient.__init__(self, url, protocols, extensions)
def __init__(self, url, protocols=None, extensions=None, io_loop=None,custom_headers=[]):
WebSocketBaseClient.__init__(self, url, protocols, extensions, custom_headers)
parts = urlsplit(self.url)
if parts.scheme == "wss":
self.sock = ssl.wrap_socket(self.sock,
Expand All @@ -24,7 +24,7 @@ def __init__(self, url, protocols=None, extensions=None, io_loop=None):

def connect(self):
parts = urlsplit(self.url)
host, port = parts.netloc, 80
host, port = parts.netloc, 443 if parts.scheme == "wss" else 80
if ':' in host:
host, port = parts.netloc.split(':')
self.io.set_close_callback(self.__connection_refused)
Expand Down