From a93c7f6ef123c06f87bec267f940b00fdaecfadc Mon Sep 17 00:00:00 2001 From: Kauppine <24810630+kauppine@users.noreply.github.com> Date: Fri, 9 Apr 2021 20:40:06 +0300 Subject: [PATCH 1/3] Added proxy support for websocket --- lib/request/connect.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/request/connect.py b/lib/request/connect.py index 56f7c73363f..a3a4f343cfd 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -506,9 +506,23 @@ def getPage(**kwargs): url = getBytes(url) # Note: Python3 requires text while Python2 has problems when mixing text with binary POST if webSocket: + ws_proxy_port = None + ws_proxy_host = None + ws_proxy_auth = None + + if conf.proxy: + ws_proxy_uri = _urllib.parse.urlsplit(conf.proxy) + ws_proxy_port = ws_proxy_uri.port + ws_proxy_host = ws_proxy_uri.netloc.split(":")[0] + + if conf.proxyCred: + ws_proxy_auth = conf.proxyCred.split(":") + ws = websocket.WebSocket() ws.settimeout(WEBSOCKET_INITIAL_TIMEOUT if kb.webSocketRecvCount is None else timeout) - ws.connect(url, header=("%s: %s" % _ for _ in headers.items() if _[0] not in ("Host",)), cookie=cookie) # WebSocket will add Host field of headers automatically + ws.connect(url, header=("%s: %s" % _ for _ in headers.items() if _[0] not in ("Host",)), cookie=cookie, + http_proxy_host=ws_proxy_host, http_proxy_port=ws_proxy_port, + http_proxy_auth=ws_proxy_auth) # WebSocket will add Host field of headers automatically ws.send(urldecode(post or "")) _page = [] From 121caadf6b56d2b982b4ccb8b00ddd72dd0d4707 Mon Sep 17 00:00:00 2001 From: Kauppine <24810630+kauppine@users.noreply.github.com> Date: Sat, 10 Apr 2021 08:29:28 +0300 Subject: [PATCH 2/3] Added missing proxy type --- lib/request/connect.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/request/connect.py b/lib/request/connect.py index a3a4f343cfd..db756831ccf 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -509,11 +509,13 @@ def getPage(**kwargs): ws_proxy_port = None ws_proxy_host = None ws_proxy_auth = None + ws_proxy_scheme = None if conf.proxy: ws_proxy_uri = _urllib.parse.urlsplit(conf.proxy) ws_proxy_port = ws_proxy_uri.port ws_proxy_host = ws_proxy_uri.netloc.split(":")[0] + ws_proxy_scheme = ws_proxy_uri.scheme if conf.proxyCred: ws_proxy_auth = conf.proxyCred.split(":") @@ -522,7 +524,7 @@ def getPage(**kwargs): ws.settimeout(WEBSOCKET_INITIAL_TIMEOUT if kb.webSocketRecvCount is None else timeout) ws.connect(url, header=("%s: %s" % _ for _ in headers.items() if _[0] not in ("Host",)), cookie=cookie, http_proxy_host=ws_proxy_host, http_proxy_port=ws_proxy_port, - http_proxy_auth=ws_proxy_auth) # WebSocket will add Host field of headers automatically + http_proxy_auth=ws_proxy_auth, proxy_type=ws_proxy_scheme) # WebSocket will add Host field of headers automatically ws.send(urldecode(post or "")) _page = [] From 7f1119e36dc0a9000bd4aa421c58371f36cfd591 Mon Sep 17 00:00:00 2001 From: Kauppine <24810630+kauppine@users.noreply.github.com> Date: Sat, 10 Apr 2021 12:57:12 +0300 Subject: [PATCH 3/3] Replaced netloc with hostname --- lib/request/connect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/request/connect.py b/lib/request/connect.py index db756831ccf..78a79141b6a 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -514,7 +514,7 @@ def getPage(**kwargs): if conf.proxy: ws_proxy_uri = _urllib.parse.urlsplit(conf.proxy) ws_proxy_port = ws_proxy_uri.port - ws_proxy_host = ws_proxy_uri.netloc.split(":")[0] + ws_proxy_host = ws_proxy_uri.hostname ws_proxy_scheme = ws_proxy_uri.scheme if conf.proxyCred: