fixed #171
This commit is contained in:
@@ -5,6 +5,7 @@ ChangeLog
|
|||||||
|
|
||||||
- fixed if client is behind proxy (#169)
|
- fixed if client is behind proxy (#169)
|
||||||
- support SNI for python 2.7.9+ and 3.2+ (#172)
|
- support SNI for python 2.7.9+ and 3.2+ (#172)
|
||||||
|
- update Host HTTP header by user. (#171)
|
||||||
|
|
||||||
- 0.29.0
|
- 0.29.0
|
||||||
|
|
||||||
|
@@ -122,7 +122,8 @@ class WebSocketApp(object):
|
|||||||
ping_interval=0, ping_timeout=None,
|
ping_interval=0, ping_timeout=None,
|
||||||
http_proxy_host=None, http_proxy_port=None,
|
http_proxy_host=None, http_proxy_port=None,
|
||||||
http_no_proxy=None, http_proxy_auth=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.
|
run event loop for WebSocket framework.
|
||||||
This loop is infinite loop and is alive during websocket is available.
|
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_proxy_port: http proxy port. If not set, set to 80.
|
||||||
http_no_proxy: host names, which doesn't use proxy.
|
http_no_proxy: host names, which doesn't use proxy.
|
||||||
skip_utf8_validation: skip utf8 validation.
|
skip_utf8_validation: skip utf8 validation.
|
||||||
|
host: update host header.
|
||||||
|
origin: update origin header.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not ping_timeout or ping_timeout <= 0:
|
if not ping_timeout or ping_timeout <= 0:
|
||||||
@@ -161,7 +164,8 @@ class WebSocketApp(object):
|
|||||||
http_proxy_host=http_proxy_host,
|
http_proxy_host=http_proxy_host,
|
||||||
http_proxy_port=http_proxy_port,
|
http_proxy_port=http_proxy_port,
|
||||||
http_no_proxy=http_no_proxy, http_proxy_auth=http_proxy_auth,
|
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)
|
self._callback(self.on_open)
|
||||||
|
|
||||||
if ping_interval:
|
if ping_interval:
|
||||||
|
@@ -76,6 +76,8 @@ def create_connection(url, timeout=None, **options):
|
|||||||
|
|
||||||
options: "header" -> custom http header list.
|
options: "header" -> custom http header list.
|
||||||
"cookie" -> cookie value.
|
"cookie" -> cookie value.
|
||||||
|
"origin" -> custom origin url.
|
||||||
|
"host" -> custom host header string.
|
||||||
"http_proxy_host" - http proxy host name.
|
"http_proxy_host" - http proxy host name.
|
||||||
"http_proxy_port" - http proxy port. If not set, set to 80.
|
"http_proxy_port" - http proxy port. If not set, set to 80.
|
||||||
"http_no_proxy" - host names, which doesn't use proxy.
|
"http_no_proxy" - host names, which doesn't use proxy.
|
||||||
@@ -237,6 +239,7 @@ class WebSocket(object):
|
|||||||
options: "header" -> custom http header list.
|
options: "header" -> custom http header list.
|
||||||
"cookie" -> cookie value.
|
"cookie" -> cookie value.
|
||||||
"origin" -> custom origin url.
|
"origin" -> custom origin url.
|
||||||
|
"host" -> custom host header string.
|
||||||
"http_proxy_host" - http proxy host name.
|
"http_proxy_host" - http proxy host name.
|
||||||
"http_proxy_port" - http proxy port. If not set, set to 80.
|
"http_proxy_port" - http proxy port. If not set, set to 80.
|
||||||
"http_no_proxy" - host names, which doesn't use proxy.
|
"http_no_proxy" - host names, which doesn't use proxy.
|
||||||
|
@@ -47,8 +47,8 @@ class handshake_response(object):
|
|||||||
self.headers = headers
|
self.headers = headers
|
||||||
self.subprotocol = subprotocol
|
self.subprotocol = subprotocol
|
||||||
|
|
||||||
def handshake(sock, host, port, resource, **options):
|
def handshake(sock, hostname, port, resource, **options):
|
||||||
headers, key = _get_handshake_headers(resource, host, port, options)
|
headers, key = _get_handshake_headers(resource, hostname, port, options)
|
||||||
|
|
||||||
header_str = "\r\n".join(headers)
|
header_str = "\r\n".join(headers)
|
||||||
send(sock, header_str)
|
send(sock, header_str)
|
||||||
@@ -71,9 +71,13 @@ def _get_handshake_headers(resource, host, port, options):
|
|||||||
hostport = host
|
hostport = host
|
||||||
else:
|
else:
|
||||||
hostport = "%s:%d" % (host, port)
|
hostport = "%s:%d" % (host, port)
|
||||||
|
|
||||||
|
if "host" in options and options["host"]:
|
||||||
|
headers.append("Host: %s" % options["host"])
|
||||||
|
else:
|
||||||
headers.append("Host: %s" % hostport)
|
headers.append("Host: %s" % hostport)
|
||||||
|
|
||||||
if "origin" in options:
|
if "origin" in options and options["origin"]:
|
||||||
headers.append("Origin: %s" % options["origin"])
|
headers.append("Origin: %s" % options["origin"])
|
||||||
else:
|
else:
|
||||||
headers.append("Origin: http://%s" % hostport)
|
headers.append("Origin: http://%s" % hostport)
|
||||||
|
Reference in New Issue
Block a user