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

Stub out GET presence requests in the frontend proxy #7545

Merged
merged 2 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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