Skip to content

Commit

Permalink
Fix breakage with aiohttp>=3.10.0 when using GCM and an HTTP proxy (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 authored Oct 2, 2024
1 parent 345aa61 commit 92f555f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog.d/395.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix incompatibility with `aiohttp>=3.10.0` when using GCM with an HTTP proxy.
27 changes: 17 additions & 10 deletions sygnal/gcmpushkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,8 @@ def __init__(self, name: str, sygnal: "Sygnal", config: Dict[str, Any]) -> None:
f"`service_account_file` must be valid: {str(e)}",
)

session = None
if proxy_url:
# `ClientSession` can't directly take the proxy URL, so we need to
# set the usual env var and use `trust_env=True`
os.environ["HTTPS_PROXY"] = proxy_url
session = aiohttp.ClientSession(trust_env=True, auto_decompress=False)

self.google_auth_request = google.auth.transport._aiohttp_requests.Request(
session=session
)
# This is instantiated in `self.create`
self.google_auth_request: google.auth.transport._aiohttp_requests.Request

# Use the fcm_options config dictionary as a foundation for the body;
# this lets the Sygnal admin choose custom FCM options
Expand All @@ -241,6 +233,21 @@ async def create(
Returns:
an instance of this Pushkin
"""
session = None
proxy_url = sygnal.config.get("proxy")
if proxy_url:
# `ClientSession` can't directly take the proxy URL, so we need to
# set the usual env var and use `trust_env=True`
os.environ["HTTPS_PROXY"] = proxy_url

# ClientSession must be instantiated by an async function, hence we do this
# here instead of `__init__`.
session = aiohttp.ClientSession(trust_env=True, auto_decompress=False)

cls.google_auth_request = google.auth.transport._aiohttp_requests.Request(
session=session
)

return cls(name, sygnal, config)

async def _perform_http_request(
Expand Down

0 comments on commit 92f555f

Please sign in to comment.