mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
MatrixFederationHttpClient: clean up
rename _create_request to _request, and push ascii-encoding of `destination` and `path` down into it
This commit is contained in:
parent
d101488c5f
commit
ad8a26e361
@ -103,11 +103,15 @@ class MatrixFederationHttpClient(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def _create_request(self, destination, method, path_bytes,
|
def _request(self, destination, method, path,
|
||||||
body_callback, headers_dict={}, param_bytes=b"",
|
body_callback, headers_dict={}, param_bytes=b"",
|
||||||
query_bytes=b"", retry_on_dns_fail=True,
|
query_bytes=b"", retry_on_dns_fail=True,
|
||||||
timeout=None, long_retries=False):
|
timeout=None, long_retries=False):
|
||||||
""" Creates and sends a request to the given url
|
""" Creates and sends a request to the given server
|
||||||
|
Args:
|
||||||
|
destination (str): The remote server to send the HTTP request to.
|
||||||
|
method (str): HTTP method
|
||||||
|
path (str): The HTTP path
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Deferred: resolves with the http response object on success.
|
Deferred: resolves with the http response object on success.
|
||||||
@ -115,6 +119,9 @@ class MatrixFederationHttpClient(object):
|
|||||||
Fails with ``HTTPRequestException``: if we get an HTTP response
|
Fails with ``HTTPRequestException``: if we get an HTTP response
|
||||||
code >= 300.
|
code >= 300.
|
||||||
"""
|
"""
|
||||||
|
destination = destination.encode("ascii")
|
||||||
|
path_bytes = path.encode("ascii")
|
||||||
|
|
||||||
headers_dict[b"User-Agent"] = [self.version_string]
|
headers_dict[b"User-Agent"] = [self.version_string]
|
||||||
headers_dict[b"Host"] = [destination]
|
headers_dict[b"Host"] = [destination]
|
||||||
|
|
||||||
@ -288,10 +295,10 @@ class MatrixFederationHttpClient(object):
|
|||||||
producer = _JsonProducer(json_data)
|
producer = _JsonProducer(json_data)
|
||||||
return producer
|
return producer
|
||||||
|
|
||||||
response = yield self._create_request(
|
response = yield self._request(
|
||||||
destination.encode("ascii"),
|
destination,
|
||||||
"PUT",
|
"PUT",
|
||||||
path.encode("ascii"),
|
path,
|
||||||
body_callback=body_callback,
|
body_callback=body_callback,
|
||||||
headers_dict={"Content-Type": ["application/json"]},
|
headers_dict={"Content-Type": ["application/json"]},
|
||||||
long_retries=long_retries,
|
long_retries=long_retries,
|
||||||
@ -333,10 +340,10 @@ class MatrixFederationHttpClient(object):
|
|||||||
)
|
)
|
||||||
return _JsonProducer(data)
|
return _JsonProducer(data)
|
||||||
|
|
||||||
response = yield self._create_request(
|
response = yield self._request(
|
||||||
destination.encode("ascii"),
|
destination,
|
||||||
"POST",
|
"POST",
|
||||||
path.encode("ascii"),
|
path,
|
||||||
body_callback=body_callback,
|
body_callback=body_callback,
|
||||||
headers_dict={"Content-Type": ["application/json"]},
|
headers_dict={"Content-Type": ["application/json"]},
|
||||||
long_retries=long_retries,
|
long_retries=long_retries,
|
||||||
@ -386,10 +393,10 @@ class MatrixFederationHttpClient(object):
|
|||||||
self.sign_request(destination, method, url_bytes, headers_dict)
|
self.sign_request(destination, method, url_bytes, headers_dict)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
response = yield self._create_request(
|
response = yield self._request(
|
||||||
destination.encode("ascii"),
|
destination,
|
||||||
"GET",
|
"GET",
|
||||||
path.encode("ascii"),
|
path,
|
||||||
query_bytes=query_bytes,
|
query_bytes=query_bytes,
|
||||||
body_callback=body_callback,
|
body_callback=body_callback,
|
||||||
retry_on_dns_fail=retry_on_dns_fail,
|
retry_on_dns_fail=retry_on_dns_fail,
|
||||||
@ -434,10 +441,10 @@ class MatrixFederationHttpClient(object):
|
|||||||
self.sign_request(destination, method, url_bytes, headers_dict)
|
self.sign_request(destination, method, url_bytes, headers_dict)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
response = yield self._create_request(
|
response = yield self._request(
|
||||||
destination.encode("ascii"),
|
destination,
|
||||||
"GET",
|
"GET",
|
||||||
path.encode("ascii"),
|
path,
|
||||||
query_bytes=query_bytes,
|
query_bytes=query_bytes,
|
||||||
body_callback=body_callback,
|
body_callback=body_callback,
|
||||||
retry_on_dns_fail=retry_on_dns_fail
|
retry_on_dns_fail=retry_on_dns_fail
|
||||||
|
Loading…
Reference in New Issue
Block a user