Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix breakage with aiohttp>=3.10.0 when using GCM and an HTTP proxy #395

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading