Skip to content

Commit 769bc57

Browse files
committed
add proxy authentication supporting for websocket (stream/ws_client.py)
1 parent b0afc93 commit 769bc57

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

stream/ws_client.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from six import StringIO
3030

3131
from websocket import WebSocket, ABNF, enableTrace
32+
from base64 import b64decode
3233

3334
STDIN_CHANNEL = 0
3435
STDOUT_CHANNEL = 1
@@ -445,11 +446,20 @@ def create_websocket(configuration, url, headers=None):
445446
ssl_opts['keyfile'] = configuration.key_file
446447

447448
websocket = WebSocket(sslopt=ssl_opts, skip_utf8_validation=False)
449+
connect_opt = {
450+
'header': header
451+
}
448452
if configuration.proxy:
449453
proxy_url = urlparse(configuration.proxy)
450-
websocket.connect(url, header=header, http_proxy_host=proxy_url.hostname, http_proxy_port=proxy_url.port)
451-
else:
452-
websocket.connect(url, header=header)
454+
connect_opt.update({'http_proxy_host': proxy_url.hostname, 'http_proxy_port': proxy_url.port})
455+
if configuration.proxy_headers:
456+
for key,value in configuration.proxy_headers.items():
457+
if key == 'proxy-authorization' and value.startswith('Basic'):
458+
b64value = value.split()[1]
459+
auth = b64decode(b64value).decode().split(':')
460+
connect_opt.update({'http_proxy_auth': (auth[0], auth[1]) })
461+
462+
websocket.connect(url, **connect_opt)
453463
return websocket
454464

455465

0 commit comments

Comments
 (0)