Skip to content

Commit

Permalink
Merge pull request #21 from toxicvengeance/user-agent
Browse files Browse the repository at this point in the history
add default user-agent to mta-sts policy lookups
  • Loading branch information
Snawoot authored Apr 16, 2019
2 parents 4ad115f + aa32aee commit 1bd5c28
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions postfix_mta_sts_resolver/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
SQLITE_TIMEOUT = 5
REDIS_TIMEOUT = 5
CACHE_GRACE = 60
USER_AGENT = "postfix-mta-sts-resolver"
7 changes: 6 additions & 1 deletion postfix_mta_sts_resolver/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def __init__(self, *, timeout=defaults.TIMEOUT, loop):
self._http_timeout = aiohttp.ClientTimeout(total=timeout)
self._proxy_info = aiohttp.helpers.proxies_from_env().get('https',
None)
self._headers = {}

if self._proxy_info is None:
self._proxy = None
self._proxy_auth = None
Expand Down Expand Up @@ -86,14 +88,17 @@ async def resolve(self, domain, last_known_id=None):
domain +
'/.well-known/mta-sts.txt')

# Construct headers for MTA-STS policy fetch
self._headers["User-Agent"] = defaults.USER_AGENT

# 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,
proxy=self._proxy,
proxy=self._proxy, headers=self._headers,
proxy_auth=self._proxy_auth) as resp:
if resp.status != 200:
raise BadSTSPolicy()
Expand Down

0 comments on commit 1bd5c28

Please sign in to comment.