Skip to content

Commit df5765b

Browse files
committed
feat(proxy): support http(s) proxy
1 parent bc7e7a7 commit df5765b

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

volcenginesdkcore/configuration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ def __init__(self):
127127

128128
# Proxy URL
129129
self.proxy = None
130+
self.http_proxy = None
131+
self.https_proxy = None
132+
self.no_proxy = None
133+
130134
# Safe chars for path_param
131135
self.safe_chars_for_path_param = ''
132136

volcenginesdkcore/rest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io
66
import json
77
import logging
8+
import os
89
import re
910
import ssl
1011

@@ -39,6 +40,18 @@ def getheader(self, name, default=None):
3940
return self.urllib3_response.getheader(name, default)
4041

4142

43+
def _get_no_proxy(configuration):
44+
n1 = os.environ.get('NO_PROXY')
45+
n2 = os.environ.get('no_proxy')
46+
if configuration.no_proxy:
47+
return configuration.no_proxy.split(',')
48+
elif n1:
49+
return n1.split(',')
50+
elif n2:
51+
return n2.split(',')
52+
return []
53+
54+
4255
class RESTClientObject(object):
4356

4457
def __init__(self, configuration, pools_size=4, maxsize=None):
@@ -78,6 +91,13 @@ def __init__(self, configuration, pools_size=4, maxsize=None):
7891
connect=configuration.connect_timeout,
7992
read=configuration.read_timeout,
8093
)
94+
95+
if configuration.proxy is None or configuration.host not in _get_no_proxy(configuration):
96+
if configuration.http_proxy and configuration.scheme == 'http':
97+
configuration.proxy = configuration.http_proxy
98+
elif configuration.https_proxy and configuration.scheme == 'https':
99+
configuration.proxy = configuration.https_proxy
100+
81101
# https pool manager
82102
if configuration.proxy:
83103
self.pool_manager = urllib3.ProxyManager(

0 commit comments

Comments
 (0)