From 92f6503131e7f15f5db06cb6eea530a721e578c8 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 20 May 2020 22:11:30 +0100 Subject: [PATCH] Stub out GET presence requests in the frontend proxy We don't really make any promises about returning accurate presence data when presence is disabled, so we may as well just return a static response, rather than making the master handle a request. --- changelog.d/7545.misc | 1 + synapse/app/generic_worker.py | 21 ++++----------------- 2 files changed, 5 insertions(+), 17 deletions(-) create mode 100644 changelog.d/7545.misc diff --git a/changelog.d/7545.misc b/changelog.d/7545.misc new file mode 100644 index 000000000000..177ec883e206 --- /dev/null +++ b/changelog.d/7545.misc @@ -0,0 +1 @@ +Make worker processes return a stubbed-out response to `GET /presence` requests. diff --git a/synapse/app/generic_worker.py b/synapse/app/generic_worker.py index 667ad204289a..d78c79e0f925 100644 --- a/synapse/app/generic_worker.py +++ b/synapse/app/generic_worker.py @@ -27,7 +27,7 @@ import synapse import synapse.events from synapse.api.constants import EventTypes -from synapse.api.errors import HttpResponseException, SynapseError +from synapse.api.errors import SynapseError from synapse.api.urls import ( CLIENT_API_PREFIX, FEDERATION_PREFIX, @@ -140,31 +140,18 @@ class PresenceStatusStubServlet(RestServlet): """If presence is disabled this servlet can be used to stub out setting - presence status, while proxying the getters to the master instance. + presence status. """ PATTERNS = client_patterns("/presence/(?P[^/]*)/status") def __init__(self, hs): super(PresenceStatusStubServlet, self).__init__() - self.http_client = hs.get_simple_http_client() self.auth = hs.get_auth() - self.main_uri = hs.config.worker_main_http_uri async def on_GET(self, request, user_id): - # Pass through the auth headers, if any, in case the access token - # is there. - auth_headers = request.requestHeaders.getRawHeaders("Authorization", []) - headers = {"Authorization": auth_headers} - - try: - result = await self.http_client.get_json( - self.main_uri + request.uri.decode("ascii"), headers=headers - ) - except HttpResponseException as e: - raise e.to_synapse_error() - - return 200, result + await self.auth.get_user_by_req(request) + return 200, {"presence": "offline"} async def on_PUT(self, request, user_id): await self.auth.get_user_by_req(request)