Merge pull request #1119 from malvidin/https_adapter

Add HTTPS Adapter
pull/1120/head
Raphaël Vinot 2023-12-15 13:03:28 +01:00 committed by GitHub
commit e8ecb3fe1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -151,13 +151,15 @@ class PyMISP:
:param auth: The auth parameter is passed directly to requests, as described here: http://docs.python-requests.org/en/master/user/authentication/ :param auth: The auth parameter is passed directly to requests, as described here: http://docs.python-requests.org/en/master/user/authentication/
:param tool: The software using PyMISP (string), used to set a unique user-agent :param tool: The software using PyMISP (string), used to set a unique user-agent
:param http_headers: Arbitrary headers to pass to all the requests. :param http_headers: Arbitrary headers to pass to all the requests.
:param https_adapter: Arbitrary HTTPS adapter for the requests session.
:param timeout: Timeout, as described here: https://requests.readthedocs.io/en/master/user/advanced/#timeouts :param timeout: Timeout, as described here: https://requests.readthedocs.io/en/master/user/advanced/#timeouts
""" """
def __init__(self, url: str, key: str, ssl: bool = True, debug: bool = False, proxies: Optional[MutableMapping[str, str]] = None, def __init__(self, url: str, key: str, ssl: Union[bool, str] = True, debug: bool = False, proxies: Optional[MutableMapping[str, str]] = None,
cert: Optional[Union[str, Tuple[str, str]]] = None, auth: Optional[AuthBase] = None, tool: str = '', cert: Optional[Union[str, Tuple[str, str]]] = None, auth: Optional[AuthBase] = None, tool: str = '',
timeout: Optional[Union[float, Tuple[float, float]]] = None, timeout: Optional[Union[float, Tuple[float, float]]] = None,
http_headers: Optional[Dict[str, str]]=None http_headers: Optional[Dict[str, str]] = None,
https_adapter: Optional[requests.adapters.BaseAdapter] = None
): ):
if not url: if not url:
@ -167,13 +169,15 @@ class PyMISP:
self.root_url: str = url self.root_url: str = url
self.key: str = key self.key: str = key
self.ssl: bool = ssl self.ssl: Union[bool, str] = ssl
self.proxies: Optional[MutableMapping[str, str]] = proxies self.proxies: Optional[MutableMapping[str, str]] = proxies
self.cert: Optional[Union[str, Tuple[str, str]]] = cert self.cert: Optional[Union[str, Tuple[str, str]]] = cert
self.auth: Optional[AuthBase] = auth self.auth: Optional[AuthBase] = auth
self.tool: str = tool self.tool: str = tool
self.timeout: Optional[Union[float, Tuple[float, float]]] = timeout self.timeout: Optional[Union[float, Tuple[float, float]]] = timeout
self.__session = requests.Session() # use one session to keep connection between requests self.__session = requests.Session() # use one session to keep connection between requests
if https_adapter is not None:
self.__session.mount('https://', https_adapter)
if brotli_supported(): if brotli_supported():
self.__session.headers['Accept-Encoding'] = ', '.join(('br', 'gzip', 'deflate')) self.__session.headers['Accept-Encoding'] = ', '.join(('br', 'gzip', 'deflate'))
if http_headers: if http_headers: