This commit is contained in:
liris
2015-04-14 13:45:11 +09:00
parent 59d564fbd1
commit b37e7e0c7c
4 changed files with 18 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ ChangeLog
- fixed if client is behind proxy (#169)
- support SNI for python 2.7.9+ and 3.2+ (#172)
- update Host HTTP header by user. (#171)
- 0.29.0

View File

@@ -122,7 +122,8 @@ class WebSocketApp(object):
ping_interval=0, ping_timeout=None,
http_proxy_host=None, http_proxy_port=None,
http_no_proxy=None, http_proxy_auth=None,
skip_utf8_validation=False):
skip_utf8_validation=False,
host=None, origin=None):
"""
run event loop for WebSocket framework.
This loop is infinite loop and is alive during websocket is available.
@@ -138,6 +139,8 @@ class WebSocketApp(object):
http_proxy_port: http proxy port. If not set, set to 80.
http_no_proxy: host names, which doesn't use proxy.
skip_utf8_validation: skip utf8 validation.
host: update host header.
origin: update origin header.
"""
if not ping_timeout or ping_timeout <= 0:
@@ -161,7 +164,8 @@ class WebSocketApp(object):
http_proxy_host=http_proxy_host,
http_proxy_port=http_proxy_port,
http_no_proxy=http_no_proxy, http_proxy_auth=http_proxy_auth,
subprotocols=self.subprotocols)
subprotocols=self.subprotocols,
host=host, origin=origin)
self._callback(self.on_open)
if ping_interval:

View File

@@ -76,6 +76,8 @@ def create_connection(url, timeout=None, **options):
options: "header" -> custom http header list.
"cookie" -> cookie value.
"origin" -> custom origin url.
"host" -> custom host header string.
"http_proxy_host" - http proxy host name.
"http_proxy_port" - http proxy port. If not set, set to 80.
"http_no_proxy" - host names, which doesn't use proxy.
@@ -237,6 +239,7 @@ class WebSocket(object):
options: "header" -> custom http header list.
"cookie" -> cookie value.
"origin" -> custom origin url.
"host" -> custom host header string.
"http_proxy_host" - http proxy host name.
"http_proxy_port" - http proxy port. If not set, set to 80.
"http_no_proxy" - host names, which doesn't use proxy.

View File

@@ -47,8 +47,8 @@ class handshake_response(object):
self.headers = headers
self.subprotocol = subprotocol
def handshake(sock, host, port, resource, **options):
headers, key = _get_handshake_headers(resource, host, port, options)
def handshake(sock, hostname, port, resource, **options):
headers, key = _get_handshake_headers(resource, hostname, port, options)
header_str = "\r\n".join(headers)
send(sock, header_str)
@@ -71,9 +71,13 @@ def _get_handshake_headers(resource, host, port, options):
hostport = host
else:
hostport = "%s:%d" % (host, port)
headers.append("Host: %s" % hostport)
if "origin" in options:
if "host" in options and options["host"]:
headers.append("Host: %s" % options["host"])
else:
headers.append("Host: %s" % hostport)
if "origin" in options and options["origin"]:
headers.append("Origin: %s" % options["origin"])
else:
headers.append("Origin: http://%s" % hostport)