new: Support for proxies to connect to the instance

This commit is contained in:
Raphaël Vinot 2023-11-21 17:23:16 +01:00
parent 208fd3d845
commit b3dcf9fe57

View file

@ -11,10 +11,13 @@ import requests
class PyVulnerabilityLookup():
def __init__(self, root_url: str, useragent: Optional[str]=None):
def __init__(self, root_url: str, useragent: Optional[str]=None,
*, proxies: Optional[Dict[str, str]]=None):
'''Query a specific instance.
:param root_url: URL of the instance to query.
:param useragent: The User Agent used by requests to run the HTTP requests against the vulnerability lookup instance
:param proxies: The proxies to use to connect to the vulnerability lookup instance - More details: https://requests.readthedocs.io/en/latest/user/advanced/#proxies
'''
self.root_url = root_url
@ -24,6 +27,8 @@ class PyVulnerabilityLookup():
self.root_url += '/'
self.session = requests.session()
self.session.headers['user-agent'] = useragent if useragent else f'PyProject / {version("pyvulnerabilitylookup")}'
if proxies:
self.session.proxies.update(proxies)
@property
def is_up(self) -> bool: