mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-09-09 14:22:02 +00:00
Stub out GET presence requests in the frontend proxy (#7545)
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.
This commit is contained in:
parent
d74cdc1a42
commit
0bbbd10513
1
changelog.d/7545.misc
Normal file
1
changelog.d/7545.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Make worker processes return a stubbed-out response to `GET /presence` requests.
|
@ -26,7 +26,7 @@ from twisted.web.resource import NoResource
|
|||||||
|
|
||||||
import synapse
|
import synapse
|
||||||
import synapse.events
|
import synapse.events
|
||||||
from synapse.api.errors import HttpResponseException, SynapseError
|
from synapse.api.errors import SynapseError
|
||||||
from synapse.api.urls import (
|
from synapse.api.urls import (
|
||||||
CLIENT_API_PREFIX,
|
CLIENT_API_PREFIX,
|
||||||
FEDERATION_PREFIX,
|
FEDERATION_PREFIX,
|
||||||
@ -137,31 +137,18 @@ logger = logging.getLogger("synapse.app.generic_worker")
|
|||||||
|
|
||||||
class PresenceStatusStubServlet(RestServlet):
|
class PresenceStatusStubServlet(RestServlet):
|
||||||
"""If presence is disabled this servlet can be used to stub out setting
|
"""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")
|
PATTERNS = client_patterns("/presence/(?P<user_id>[^/]*)/status")
|
||||||
|
|
||||||
def __init__(self, hs):
|
def __init__(self, hs):
|
||||||
super(PresenceStatusStubServlet, self).__init__()
|
super(PresenceStatusStubServlet, self).__init__()
|
||||||
self.http_client = hs.get_simple_http_client()
|
|
||||||
self.auth = hs.get_auth()
|
self.auth = hs.get_auth()
|
||||||
self.main_uri = hs.config.worker_main_http_uri
|
|
||||||
|
|
||||||
async def on_GET(self, request, user_id):
|
async def on_GET(self, request, user_id):
|
||||||
# Pass through the auth headers, if any, in case the access token
|
await self.auth.get_user_by_req(request)
|
||||||
# is there.
|
return 200, {"presence": "offline"}
|
||||||
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
|
|
||||||
|
|
||||||
async def on_PUT(self, request, user_id):
|
async def on_PUT(self, request, user_id):
|
||||||
await self.auth.get_user_by_req(request)
|
await self.auth.get_user_by_req(request)
|
||||||
|
Loading…
Reference in New Issue
Block a user