0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-11-12 04:52:26 +01:00

Replace deprecated HTTPAdapter.get_connection method with get_connection_with_tls_context (#17536)

This commit is contained in:
Andrew Morgan 2024-08-08 15:59:37 +02:00 committed by GitHub
parent 44ac2aa3b6
commit 3ad38b644d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 7 deletions

1
changelog.d/17536.misc Normal file
View file

@ -0,0 +1 @@
Replace override of deprecated method `HTTPAdapter.get_connection` with `get_connection_with_tls_context`.

View file

@ -43,7 +43,7 @@ import argparse
import base64 import base64
import json import json
import sys import sys
from typing import Any, Dict, Optional, Tuple from typing import Any, Dict, Mapping, Optional, Tuple, Union
from urllib import parse as urlparse from urllib import parse as urlparse
import requests import requests
@ -75,7 +75,7 @@ def encode_canonical_json(value: object) -> bytes:
value, value,
# Encode code-points outside of ASCII as UTF-8 rather than \u escapes # Encode code-points outside of ASCII as UTF-8 rather than \u escapes
ensure_ascii=False, ensure_ascii=False,
# Remove unecessary white space. # Remove unnecessary white space.
separators=(",", ":"), separators=(",", ":"),
# Sort the keys of dictionaries. # Sort the keys of dictionaries.
sort_keys=True, sort_keys=True,
@ -298,12 +298,23 @@ class MatrixConnectionAdapter(HTTPAdapter):
return super().send(request, *args, **kwargs) return super().send(request, *args, **kwargs)
def get_connection( def get_connection_with_tls_context(
self, url: str, proxies: Optional[Dict[str, str]] = None self,
request: PreparedRequest,
verify: Optional[Union[bool, str]],
proxies: Optional[Mapping[str, str]] = None,
cert: Optional[Union[Tuple[str, str], str]] = None,
) -> HTTPConnectionPool: ) -> HTTPConnectionPool:
# overrides the get_connection() method in the base class # overrides the get_connection_with_tls_context() method in the base class
parsed = urlparse.urlsplit(url) parsed = urlparse.urlsplit(request.url)
(host, port, ssl_server_name) = self._lookup(parsed.netloc)
# Extract the server name from the request URL, and ensure it's a str.
hostname = parsed.netloc
if isinstance(hostname, bytes):
hostname = hostname.decode("utf-8")
assert isinstance(hostname, str)
(host, port, ssl_server_name) = self._lookup(hostname)
print( print(
f"Connecting to {host}:{port} with SNI {ssl_server_name}", file=sys.stderr f"Connecting to {host}:{port} with SNI {ssl_server_name}", file=sys.stderr
) )