diff options
author | Richard van der Hoff <richard@matrix.org> | 2018-02-08 18:44:52 +0000 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2018-02-09 13:07:41 +0000 |
commit | 74fcbf741b3a7b95b5cc44478050e8a40fb7dc46 (patch) | |
tree | 99deb06ce2673f82ee4be8b5c36ddf0b51954ede /synapse/http | |
parent | purge: Move cache invalidation to more appropriate place (diff) | |
download | synapse-74fcbf741b3a7b95b5cc44478050e8a40fb7dc46.tar.xz |
delete_local_events for purge_history
Add a flag which makes the purger delete local events
Diffstat (limited to 'synapse/http')
-rw-r--r-- | synapse/http/servlet.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/synapse/http/servlet.py b/synapse/http/servlet.py index 71420e54db..ef8e62901b 100644 --- a/synapse/http/servlet.py +++ b/synapse/http/servlet.py @@ -148,11 +148,13 @@ def parse_string_from_args(args, name, default=None, required=False, return default -def parse_json_value_from_request(request): +def parse_json_value_from_request(request, allow_empty_body=False): """Parse a JSON value from the body of a twisted HTTP request. Args: request: the twisted HTTP request. + allow_empty_body (bool): if True, an empty body will be accepted and + turned into None Returns: The JSON value. @@ -165,6 +167,9 @@ def parse_json_value_from_request(request): except Exception: raise SynapseError(400, "Error reading JSON content.") + if not content_bytes and allow_empty_body: + return None + try: content = simplejson.loads(content_bytes) except Exception as e: @@ -174,17 +179,24 @@ def parse_json_value_from_request(request): return content -def parse_json_object_from_request(request): +def parse_json_object_from_request(request, allow_empty_body=False): """Parse a JSON object from the body of a twisted HTTP request. Args: request: the twisted HTTP request. + allow_empty_body (bool): if True, an empty body will be accepted and + turned into an empty dict. Raises: SynapseError if the request body couldn't be decoded as JSON or if it wasn't a JSON object. """ - content = parse_json_value_from_request(request) + content = parse_json_value_from_request( + request, allow_empty_body=allow_empty_body, + ) + + if allow_empty_body and content is None: + return {} if type(content) != dict: message = "Content must be a JSON object." |