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

Commit

Permalink
MatrixFederationHttpClient: clean up
Browse files Browse the repository at this point in the history
rename _create_request to _request, and push ascii-encoding of `destination`
and `path` down into it
  • Loading branch information
richvdh committed Mar 23, 2017
1 parent d101488 commit ad8a26e
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions synapse/http/matrixfederationclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,25 @@ def _create_url(self, destination, path_bytes, param_bytes, query_bytes):
)

@defer.inlineCallbacks
def _create_request(self, destination, method, path_bytes,
body_callback, headers_dict={}, param_bytes=b"",
query_bytes=b"", retry_on_dns_fail=True,
timeout=None, long_retries=False):
""" Creates and sends a request to the given url
def _request(self, destination, method, path,
body_callback, headers_dict={}, param_bytes=b"",
query_bytes=b"", retry_on_dns_fail=True,
timeout=None, long_retries=False):
""" 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:
Deferred: resolves with the http response object on success.
Fails with ``HTTPRequestException``: if we get an HTTP response
code >= 300.
"""
destination = destination.encode("ascii")
path_bytes = path.encode("ascii")

headers_dict[b"User-Agent"] = [self.version_string]
headers_dict[b"Host"] = [destination]

Expand Down Expand Up @@ -288,10 +295,10 @@ def body_callback(method, url_bytes, headers_dict):
producer = _JsonProducer(json_data)
return producer

response = yield self._create_request(
destination.encode("ascii"),
response = yield self._request(
destination,
"PUT",
path.encode("ascii"),
path,
body_callback=body_callback,
headers_dict={"Content-Type": ["application/json"]},
long_retries=long_retries,
Expand Down Expand Up @@ -333,10 +340,10 @@ def body_callback(method, url_bytes, headers_dict):
)
return _JsonProducer(data)

response = yield self._create_request(
destination.encode("ascii"),
response = yield self._request(
destination,
"POST",
path.encode("ascii"),
path,
body_callback=body_callback,
headers_dict={"Content-Type": ["application/json"]},
long_retries=long_retries,
Expand Down Expand Up @@ -386,10 +393,10 @@ def body_callback(method, url_bytes, headers_dict):
self.sign_request(destination, method, url_bytes, headers_dict)
return None

response = yield self._create_request(
destination.encode("ascii"),
response = yield self._request(
destination,
"GET",
path.encode("ascii"),
path,
query_bytes=query_bytes,
body_callback=body_callback,
retry_on_dns_fail=retry_on_dns_fail,
Expand Down Expand Up @@ -434,10 +441,10 @@ def body_callback(method, url_bytes, headers_dict):
self.sign_request(destination, method, url_bytes, headers_dict)
return None

response = yield self._create_request(
destination.encode("ascii"),
response = yield self._request(
destination,
"GET",
path.encode("ascii"),
path,
query_bytes=query_bytes,
body_callback=body_callback,
retry_on_dns_fail=retry_on_dns_fail
Expand Down

0 comments on commit ad8a26e

Please sign in to comment.