mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-03 08:46:55 +00:00
Add socks5 proxy support for OpenAPI generated python client (#16918)
* add socks5 proxy support (requires additional import) * updated examples * build samples. updated to support pydantic python option * rename sock to socks for correct protocol name * add proxy headers for pydantic * fixed param changes from conflict resolution
This commit is contained in:
@@ -22,8 +22,20 @@ import urllib3
|
||||
|
||||
from openapi_client.exceptions import ApiException, ApiValueError
|
||||
|
||||
SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
|
||||
RESTResponseType = urllib3.HTTPResponse
|
||||
|
||||
|
||||
def is_socks_proxy_url(url):
|
||||
if url is None:
|
||||
return False
|
||||
split_section = url.split("://")
|
||||
if len(split_section) < 2:
|
||||
return False
|
||||
else:
|
||||
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
|
||||
|
||||
|
||||
class RESTResponse(io.IOBase):
|
||||
|
||||
def __init__(self, resp) -> None:
|
||||
@@ -78,15 +90,27 @@ class RESTClientObject:
|
||||
|
||||
# https pool manager
|
||||
if configuration.proxy:
|
||||
self.pool_manager = urllib3.ProxyManager(
|
||||
cert_reqs=cert_reqs,
|
||||
ca_certs=configuration.ssl_ca_cert,
|
||||
cert_file=configuration.cert_file,
|
||||
key_file=configuration.key_file,
|
||||
proxy_url=configuration.proxy,
|
||||
proxy_headers=configuration.proxy_headers,
|
||||
**addition_pool_args
|
||||
)
|
||||
if is_socks_proxy_url(configuration.proxy):
|
||||
from urllib3.contrib.socks import SOCKSProxyManager
|
||||
self.pool_manager = SOCKSProxyManager(
|
||||
cert_reqs=cert_reqs,
|
||||
ca_certs=configuration.ssl_ca_cert,
|
||||
cert_file=configuration.cert_file,
|
||||
key_file=configuration.key_file,
|
||||
proxy_url=configuration.proxy,
|
||||
headers=configuration.proxy_headers,
|
||||
**addition_pool_args
|
||||
)
|
||||
else:
|
||||
self.pool_manager = urllib3.ProxyManager(
|
||||
cert_reqs=cert_reqs,
|
||||
ca_certs=configuration.ssl_ca_cert,
|
||||
cert_file=configuration.cert_file,
|
||||
key_file=configuration.key_file,
|
||||
proxy_url=configuration.proxy,
|
||||
proxy_headers=configuration.proxy_headers,
|
||||
**addition_pool_args
|
||||
)
|
||||
else:
|
||||
self.pool_manager = urllib3.PoolManager(
|
||||
cert_reqs=cert_reqs,
|
||||
|
||||
Reference in New Issue
Block a user