diff options
author | Mark Haines <mark.haines@matrix.org> | 2014-09-03 09:37:44 +0100 |
---|---|---|
committer | Mark Haines <mark.haines@matrix.org> | 2014-09-03 09:37:44 +0100 |
commit | 112c7ea315bdf341fc56a190138c290a5b7acffc (patch) | |
tree | 7bede512c6bff2de9ea9f5dbf364a17d4e202a9d /synapse/http/server.py | |
parent | Merge branch 'ratelimiting' into develop (diff) | |
download | synapse-112c7ea315bdf341fc56a190138c290a5b7acffc.tar.xz |
Set status message for ratelimit error responses
Diffstat (limited to 'synapse/http/server.py')
-rw-r--r-- | synapse/http/server.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py index 0b87718bfa..74c220e869 100644 --- a/synapse/http/server.py +++ b/synapse/http/server.py @@ -140,7 +140,8 @@ class JsonResource(HttpServer, resource.Resource): self._send_response( request, e.code, - cs_exception(e) + cs_exception(e), + response_code_message=e.response_code_message ) except Exception as e: logger.exception(e) @@ -150,7 +151,8 @@ class JsonResource(HttpServer, resource.Resource): {"error": "Internal server error"} ) - def _send_response(self, request, code, response_json_object): + def _send_response(self, request, code, response_json_object, + response_code_message=None): # could alternatively use request.notifyFinish() and flip a flag when # the Deferred fires, but since the flag is RIGHT THERE it seems like # a waste. @@ -166,7 +168,8 @@ class JsonResource(HttpServer, resource.Resource): json_bytes = encode_pretty_printed_json(response_json_object) # TODO: Only enable CORS for the requests that need it. - respond_with_json_bytes(request, code, json_bytes, send_cors=True) + respond_with_json_bytes(request, code, json_bytes, send_cors=True, + response_code_message=response_code_message) @staticmethod def _request_user_agent_is_curl(request): @@ -350,7 +353,8 @@ class ContentRepoResource(resource.Resource): send_cors=True) -def respond_with_json_bytes(request, code, json_bytes, send_cors=False): +def respond_with_json_bytes(request, code, json_bytes, send_cors=False, + response_code_message=None): """Sends encoded JSON in response to the given request. Args: @@ -362,7 +366,7 @@ def respond_with_json_bytes(request, code, json_bytes, send_cors=False): Returns: twisted.web.server.NOT_DONE_YET""" - request.setResponseCode(code) + request.setResponseCode(code, message=response_code_message) request.setHeader(b"Content-Type", b"application/json") if send_cors: |