From 373ff4bda9dd378fb85db9aa193f3333b829e38b Mon Sep 17 00:00:00 2001 From: Vladislav Yarmak Date: Thu, 25 Oct 2018 16:13:14 +0300 Subject: [PATCH] proxy support --- postfix_mta_sts_resolver/resolver.py | 15 +++++++++++++-- setup.py | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/postfix_mta_sts_resolver/resolver.py b/postfix_mta_sts_resolver/resolver.py index 1047f1d..18d3297 100644 --- a/postfix_mta_sts_resolver/resolver.py +++ b/postfix_mta_sts_resolver/resolver.py @@ -23,6 +23,13 @@ def __init__(self, *, timeout=defaults.TIMEOUT, loop): self._timeout = timeout self._resolver = aiodns.DNSResolver(timeout=timeout, loop=loop) self._http_timeout = aiohttp.ClientTimeout(total=timeout) + self._proxy_info = aiohttp.helpers.proxies_from_env().get('https', None) + if self._proxy_info is None: + self._proxy = None + self._proxy_auth = None + else: + self._proxy = self._proxy_info.proxy + self._proxy_auth = self._proxy_info.proxy_auth async def resolve(self, domain, last_known_id=None): if domain.startswith('.'): @@ -69,8 +76,12 @@ async def resolve(self, domain, last_known_id=None): # Fetch actual policy try: - async with aiohttp.ClientSession(loop=self._loop, timeout=self._http_timeout) as session: - async with session.get(sts_policy_url, allow_redirects=False) as resp: + async with aiohttp.ClientSession(loop=self._loop, + timeout=self._http_timeout) as session: + async with session.get(sts_policy_url, + allow_redirects=False, + proxy=self._proxy, + proxy_auth=self._proxy_auth) as resp: if resp.status != 200: raise BadSTSPolicy() if not is_plaintext(resp.headers.get('Content-Type', '')): diff --git a/setup.py b/setup.py index 6b751be..146d593 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ long_description = f.read() setup(name='postfix_mta_sts_resolver', - version='0.2.0', + version='0.2.1', description='Daemon which provides TLS client policy for Postfix via socketmap, according to domain MTA-STS policy', url='https://github.com/Snawoot/postfix-mta-sts-resolver', author='Vladislav Yarmak',