Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

HTTP Replication Client #15470

Merged
merged 17 commits into from
May 9, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Several things:
1. Fixed linting oddness from suggested review commits(extra spaces removal)
2. Inlined _getEndpoint() and removed dead function
3. Removed a backwards compatibility code that was not needed(this did need to have an argument changed for the __init__() function to make it not Optional)
4. Fixed up some docstrings(removed redundant bits and streamlined)
  • Loading branch information
realtyem committed May 9, 2023
commit 144474d5d0f3d5ae8b5f638c3108111127fe9cf9
29 changes: 4 additions & 25 deletions synapse/http/replicationagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
URI,
HTTPConnectionPool,
_AgentBase,
_DeprecatedToCurrentPolicyForHTTPS,
)
from twisted.web.error import SchemeNotSupported
from twisted.web.http_headers import Headers
Expand Down Expand Up @@ -78,18 +77,14 @@ def endpointForURI(self, uri: URI) -> IStreamClientEndpoint:
class ReplicationAgent(_AgentBase):
"""
Client for connecting to replication endpoints via HTTP and HTTPS.

Much of this code is copied from Twisted's twisted.web.client.Agent.

Attributes:
_endpointFactory: The IAgentEndpointFactory which will
be used to create endpoints for outgoing TCP connections.
Much of this code is copied from Twisted's twisted.web.client.Agent.
"""

def __init__(
self,
reactor: ISynapseReactor,
contextFactory: Optional[IPolicyForHTTPS] = None,
contextFactory: IPolicyForHTTPS,
connectTimeout: Optional[float] = None,
bindAddress: Optional[bytes] = None,
pool: Optional[HTTPConnectionPool] = None,
Expand All @@ -110,26 +105,10 @@ def __init__(
case a non-persistent HTTPConnectionPool instance will be
created.
"""
if not IPolicyForHTTPS.providedBy(contextFactory):
logger.warning(
f"{contextFactory} was passed as the HTTPS policy for an "
"Agent, but it does not provide IPolicyForHTTPS. Since Twisted 14.0, "
"you must pass a provider of IPolicyForHTTPS.",
)
contextFactory = _DeprecatedToCurrentPolicyForHTTPS(contextFactory)

_AgentBase.__init__(self, reactor, pool)
endpoint_factory = ReplicationEndpointFactory(reactor, contextFactory)
self._endpointFactory = endpoint_factory

def _getEndpoint(self, uri: URI) -> IStreamClientEndpoint:
"""
Get an endpoint for the given URI, using self._endpointFactory.
uri: The URI of the request.
Returns: An endpoint which can be used to connect to given address.
"""
return self._endpointFactory.endpointForURI(uri)

def request(
self,
method: bytes,
Expand All @@ -146,7 +125,7 @@ def request(
Currently, HTTP and HTTPS schemes are supported in uri.

This is copied from twisted.web.client.Agent, except:

* It uses a different pool key (combining the host & port).
* It does not call _ensureValidURI(...) since it breaks on some
UNIX paths.
Expand All @@ -155,7 +134,7 @@ def request(
"""
parsedURI = URI.fromBytes(uri)
try:
endpoint = self._getEndpoint(parsedURI)
endpoint = self._endpointFactory.endpointForURI(parsedURI)
except SchemeNotSupported:
return defer.fail(Failure())

Expand Down