mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-11-29 14:09:15 -05:00
Include a user agent in federation requests. (#7677)
This commit is contained in:
parent
a3f11567d9
commit
ac51bd581a
5 changed files with 43 additions and 4 deletions
|
|
@ -48,6 +48,9 @@ class MatrixFederationAgent(object):
|
|||
tls_client_options_factory (FederationPolicyForHTTPS|None):
|
||||
factory to use for fetching client tls options, or none to disable TLS.
|
||||
|
||||
user_agent (bytes):
|
||||
The user agent header to use for federation requests.
|
||||
|
||||
_srv_resolver (SrvResolver|None):
|
||||
SRVResolver impl to use for looking up SRV records. None to use a default
|
||||
implementation.
|
||||
|
|
@ -61,6 +64,7 @@ class MatrixFederationAgent(object):
|
|||
self,
|
||||
reactor,
|
||||
tls_client_options_factory,
|
||||
user_agent,
|
||||
_srv_resolver=None,
|
||||
_well_known_resolver=None,
|
||||
):
|
||||
|
|
@ -78,6 +82,7 @@ class MatrixFederationAgent(object):
|
|||
),
|
||||
pool=self._pool,
|
||||
)
|
||||
self.user_agent = user_agent
|
||||
|
||||
if _well_known_resolver is None:
|
||||
_well_known_resolver = WellKnownResolver(
|
||||
|
|
@ -87,6 +92,7 @@ class MatrixFederationAgent(object):
|
|||
pool=self._pool,
|
||||
contextFactory=tls_client_options_factory,
|
||||
),
|
||||
user_agent=self.user_agent,
|
||||
)
|
||||
|
||||
self._well_known_resolver = _well_known_resolver
|
||||
|
|
@ -149,7 +155,7 @@ class MatrixFederationAgent(object):
|
|||
parsed_uri = urllib.parse.urlparse(uri)
|
||||
|
||||
# We need to make sure the host header is set to the netloc of the
|
||||
# server.
|
||||
# server and that a user-agent is provided.
|
||||
if headers is None:
|
||||
headers = Headers()
|
||||
else:
|
||||
|
|
@ -157,6 +163,8 @@ class MatrixFederationAgent(object):
|
|||
|
||||
if not headers.hasHeader(b"host"):
|
||||
headers.addRawHeader(b"host", parsed_uri.netloc)
|
||||
if not headers.hasHeader(b"user-agent"):
|
||||
headers.addRawHeader(b"user-agent", self.user_agent)
|
||||
|
||||
res = yield make_deferred_yieldable(
|
||||
self._agent.request(method, uri, headers, bodyProducer)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue