Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit 09dbbe5

Browse files
authored
Merge pull request #260 from itaru2622/no_proxy
add no_proxy support to websocket client
2 parents 51460f4 + 4ef4139 commit 09dbbe5

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

stream/ws_client.py

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
from websocket import WebSocket, ABNF, enableTrace
3232
from base64 import urlsafe_b64decode
33+
from requests.utils import should_bypass_proxies
3334

3435
STDIN_CHANNEL = 0
3536
STDOUT_CHANNEL = 1
@@ -457,6 +458,12 @@ def create_websocket(configuration, url, headers=None):
457458
return websocket
458459

459460
def websocket_proxycare(connect_opt, configuration, url, headers):
461+
""" An internal function to be called in api-client when a websocket
462+
create is requested.
463+
"""
464+
if configuration.no_proxy:
465+
connect_opt.update({ 'http_no_proxy': configuration.no_proxy.split(',') })
466+
460467
if configuration.proxy:
461468
proxy_url = urlparse(configuration.proxy)
462469
connect_opt.update({'http_proxy_host': proxy_url.hostname, 'http_proxy_port': proxy_url.port})

stream/ws_client_test.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,30 @@ def test_websocket_client(self):
4747
self.assertEqual(get_websocket_url(url), ws_url)
4848

4949
def test_websocket_proxycare(self):
50-
for proxy, idpass, expect_host, expect_port, expect_auth in [
51-
( None, None, None, None, None ),
52-
( 'http://proxy.example.com:8080/', None, 'proxy.example.com', 8080, None ),
53-
( 'http://proxy.example.com:8080/', 'user:pass', 'proxy.example.com', 8080, ('user','pass'))
50+
for proxy, idpass, no_proxy, expect_host, expect_port, expect_auth, expect_noproxy in [
51+
( None, None, None, None, None, None, None ),
52+
( 'http://proxy.example.com:8080/', None, None, 'proxy.example.com', 8080, None, None ),
53+
( 'http://proxy.example.com:8080/', 'user:pass', None, 'proxy.example.com', 8080, ('user','pass'), None),
54+
( 'http://proxy.example.com:8080/', 'user:pass', '', 'proxy.example.com', 8080, ('user','pass'), None),
55+
( 'http://proxy.example.com:8080/', 'user:pass', '*', 'proxy.example.com', 8080, ('user','pass'), ['*']),
56+
( 'http://proxy.example.com:8080/', 'user:pass', '.example.com', 'proxy.example.com', 8080, ('user','pass'), ['.example.com']),
57+
( 'http://proxy.example.com:8080/', 'user:pass', 'localhost,.local,.example.com', 'proxy.example.com', 8080, ('user','pass'), ['localhost','.local','.example.com']),
5458
]:
59+
# setup input
5560
config = Configuration()
5661
if proxy is not None:
5762
setattr(config, 'proxy', proxy)
5863
if idpass is not None:
5964
setattr(config, 'proxy_headers', urllib3.util.make_headers(proxy_basic_auth=idpass))
65+
if no_proxy is not None:
66+
setattr(config, 'no_proxy', no_proxy)
67+
# setup done
68+
# test starts
6069
connect_opt = websocket_proxycare( {}, config, None, None)
6170
self.assertEqual( dictval(connect_opt,'http_proxy_host'), expect_host)
6271
self.assertEqual( dictval(connect_opt,'http_proxy_port'), expect_port)
6372
self.assertEqual( dictval(connect_opt,'http_proxy_auth'), expect_auth)
73+
self.assertEqual( dictval(connect_opt,'http_no_proxy'), expect_noproxy)
6474

6575
if __name__ == '__main__':
6676
unittest.main()

0 commit comments

Comments
 (0)