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

Commit

Permalink
Stub out GET presence requests in the frontend proxy (#7545)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
richvdh authored May 21, 2020
1 parent d74cdc1 commit 0bbbd10
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
1 change: 1 addition & 0 deletions changelog.d/7545.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make worker processes return a stubbed-out response to `GET /presence` requests.
21 changes: 4 additions & 17 deletions synapse/app/generic_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import synapse
import synapse.events
from synapse.api.errors import HttpResponseException, SynapseError
from synapse.api.errors import SynapseError
from synapse.api.urls import (
CLIENT_API_PREFIX,
FEDERATION_PREFIX,
Expand Down Expand Up @@ -137,31 +137,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<user_id>[^/]*)/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)
Expand Down

0 comments on commit 0bbbd10

Please sign in to comment.