mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-12-26 19:09:24 -05:00
Rename POST param to METHOD
This commit is contained in:
parent
5011417632
commit
bebe325e6c
@ -40,8 +40,8 @@ class ReplicationEndpoint(object):
|
|||||||
|
|
||||||
/_synapse/replication/send_event/:event_id/:txn_id
|
/_synapse/replication/send_event/:event_id/:txn_id
|
||||||
|
|
||||||
For POST requests the payload is serialized to json and sent as the body,
|
For POST/PUT requests the payload is serialized to json and sent as the
|
||||||
while for GET requests the payload is added as query parameters. See
|
body, while for GET requests the payload is added as query parameters. See
|
||||||
`_serialize_payload` for details.
|
`_serialize_payload` for details.
|
||||||
|
|
||||||
Incoming requests are handled by overriding `_handle_request`. Servers
|
Incoming requests are handled by overriding `_handle_request`. Servers
|
||||||
@ -55,8 +55,9 @@ class ReplicationEndpoint(object):
|
|||||||
PATH_ARGS (tuple[str]): A list of parameters to be added to the path.
|
PATH_ARGS (tuple[str]): A list of parameters to be added to the path.
|
||||||
Adding parameters to the path (rather than payload) can make it
|
Adding parameters to the path (rather than payload) can make it
|
||||||
easier to follow along in the log files.
|
easier to follow along in the log files.
|
||||||
POST (bool): True to use POST request with JSON body, or false to use
|
METHOD (str): The method of the HTTP request, defaults to POST. Can be
|
||||||
GET requests with query params.
|
one of POST, PUT or GET. If GET then the payload is sent as query
|
||||||
|
parameters rather than a JSON body.
|
||||||
CACHE (bool): Whether server should cache the result of the request/
|
CACHE (bool): Whether server should cache the result of the request/
|
||||||
If true then transparently adds a txn_id to all requests, and
|
If true then transparently adds a txn_id to all requests, and
|
||||||
`_handle_request` must return a Deferred.
|
`_handle_request` must return a Deferred.
|
||||||
@ -69,7 +70,7 @@ class ReplicationEndpoint(object):
|
|||||||
NAME = abc.abstractproperty()
|
NAME = abc.abstractproperty()
|
||||||
PATH_ARGS = abc.abstractproperty()
|
PATH_ARGS = abc.abstractproperty()
|
||||||
|
|
||||||
POST = True
|
METHOD = "POST"
|
||||||
CACHE = True
|
CACHE = True
|
||||||
RETRY_ON_TIMEOUT = True
|
RETRY_ON_TIMEOUT = True
|
||||||
|
|
||||||
@ -80,6 +81,8 @@ class ReplicationEndpoint(object):
|
|||||||
timeout_ms=30 * 60 * 1000,
|
timeout_ms=30 * 60 * 1000,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assert self.METHOD in ("PUT", "POST", "GET")
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def _serialize_payload(**kwargs):
|
def _serialize_payload(**kwargs):
|
||||||
"""Static method that is called when creating a request.
|
"""Static method that is called when creating a request.
|
||||||
@ -90,9 +93,9 @@ class ReplicationEndpoint(object):
|
|||||||
argument list.
|
argument list.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Deferred[dict]|dict: If POST request then dictionary must be JSON
|
Deferred[dict]|dict: If POST/PUT request then dictionary must be
|
||||||
serialisable, otherwise must be appropriate for adding as query
|
JSON serialisable, otherwise must be appropriate for adding as
|
||||||
args.
|
query args.
|
||||||
"""
|
"""
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
@ -130,10 +133,18 @@ class ReplicationEndpoint(object):
|
|||||||
txn_id = random_string(10)
|
txn_id = random_string(10)
|
||||||
url_args.append(txn_id)
|
url_args.append(txn_id)
|
||||||
|
|
||||||
if cls.POST:
|
if cls.METHOD == "POST":
|
||||||
request_func = client.post_json_get_json
|
request_func = client.post_json_get_json
|
||||||
else:
|
elif cls.METHOD == "PUT":
|
||||||
|
request_func = client.put_json
|
||||||
|
elif cls.METHOD == "GET":
|
||||||
request_func = client.get_json
|
request_func = client.get_json
|
||||||
|
else:
|
||||||
|
# We have already asserted in the constructor that a
|
||||||
|
# compatible was picked, but lets be paranoid.
|
||||||
|
raise Exception(
|
||||||
|
"Unknown METHOD on %s replication endpoint" % (cls.NAME,)
|
||||||
|
)
|
||||||
|
|
||||||
uri = "http://%s:%s/_synapse/replication/%s/%s" % (
|
uri = "http://%s:%s/_synapse/replication/%s/%s" % (
|
||||||
host, port, cls.NAME, "/".join(url_args)
|
host, port, cls.NAME, "/".join(url_args)
|
||||||
@ -174,8 +185,7 @@ class ReplicationEndpoint(object):
|
|||||||
url_args = list(self.PATH_ARGS)
|
url_args = list(self.PATH_ARGS)
|
||||||
method = "GET"
|
method = "GET"
|
||||||
handler = self._handle_request
|
handler = self._handle_request
|
||||||
if self.POST:
|
method = self.METHOD
|
||||||
method = "POST"
|
|
||||||
|
|
||||||
if self.CACHE:
|
if self.CACHE:
|
||||||
handler = self._cached_handler
|
handler = self._cached_handler
|
||||||
|
@ -47,7 +47,6 @@ class ReplicationSendEventRestServlet(ReplicationEndpoint):
|
|||||||
"""
|
"""
|
||||||
NAME = "send_event"
|
NAME = "send_event"
|
||||||
PATH_ARGS = ("event_id",)
|
PATH_ARGS = ("event_id",)
|
||||||
POST = True
|
|
||||||
|
|
||||||
def __init__(self, hs):
|
def __init__(self, hs):
|
||||||
super(ReplicationSendEventRestServlet, self).__init__(hs)
|
super(ReplicationSendEventRestServlet, self).__init__(hs)
|
||||||
|
Loading…
Reference in New Issue
Block a user