Skip to content

Commit d4fc0b9

Browse files
committed
new: Add support for proxies.
1 parent 1ebf96e commit d4fc0b9

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

pyipasnhistory/api.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,25 @@
1717

1818
class IPASNHistory():
1919

20-
def __init__(self, root_url: str='https://ipasnhistory.circl.lu/', useragent: str | None=None) -> None:
21-
self.root_url = root_url
20+
def __init__(self, root_url: str | None=None, useragent: str | None=None,
21+
*, proxies: dict[str, str] | None=None) -> None:
22+
'''Initialize the IPASNHistory client.
23+
24+
:param root_url: URL of the IPASNHistory instance to query. Defaults to 'https://ipasnhistory.circl.lu/'.
25+
:param useragent: User-Agent to use for the requests.
26+
:param proxies: Proxies to use for the requests.
27+
'''
28+
self.root_url = root_url if root_url else 'https://ipasnhistory.circl.lu/'
2229
if not urlparse(self.root_url).scheme:
2330
self.root_url = 'http://' + self.root_url
2431
if not self.root_url.endswith('/'):
2532
self.root_url += '/'
2633
self.session = requests.session()
27-
self.session.headers['user-agent'] = useragent if useragent else f'PyIPASNHIstory / {version("pyipasnhistory")}'
2834
retries = Retry(total=5, backoff_factor=0.1, status_forcelist=[500, 502, 503, 504])
2935
self.session.mount('http://', HTTPAdapter(max_retries=retries))
36+
self.session.headers['user-agent'] = useragent if useragent else f'PyIPASNHIstory / {version("pyipasnhistory")}'
37+
if proxies:
38+
self.session.proxies.update(proxies)
3039

3140
@property
3241
def is_up(self) -> bool:

0 commit comments

Comments
 (0)