mirror of
https://github.com/matrix-org/pantalaimon.git
synced 2025-07-09 16:19:35 -04:00
daemon: Add access control headers to the search endpoint.
These headers are important for riot to be able to use pan's search endpoint instead of the default Homeserver endpoint. It fails to search using pan with CORS errors.
This commit is contained in:
parent
a2d6f3cc84
commit
1ad2a3af28
2 changed files with 17 additions and 1 deletions
|
@ -905,6 +905,17 @@ class ProxyDaemon:
|
||||||
data=json.dumps(sanitized_content)
|
data=json.dumps(sanitized_content)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def search_opts(self, request):
|
||||||
|
headers = {
|
||||||
|
"Access-Control-Allow-Headers": (
|
||||||
|
"Origin, X-Requested-With, Content-Type, Accept, Authorization"
|
||||||
|
),
|
||||||
|
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
|
||||||
|
"Access-Control-Allow-Origin": "*",
|
||||||
|
}
|
||||||
|
|
||||||
|
return web.json_response({}, headers=headers)
|
||||||
|
|
||||||
async def search(self, request):
|
async def search(self, request):
|
||||||
access_token = self.get_access_token(request)
|
access_token = self.get_access_token(request)
|
||||||
|
|
||||||
|
@ -942,7 +953,11 @@ class ProxyDaemon:
|
||||||
except UnknownRoomError:
|
except UnknownRoomError:
|
||||||
return await self.forward_to_web(request)
|
return await self.forward_to_web(request)
|
||||||
|
|
||||||
return web.json_response(result, status=200)
|
return web.json_response(
|
||||||
|
result,
|
||||||
|
headers={"Access-Control-Allow-Origin": "*"},
|
||||||
|
status=200
|
||||||
|
)
|
||||||
|
|
||||||
async def shutdown(self, _):
|
async def shutdown(self, _):
|
||||||
"""Shut the daemon down closing all the client sessions it has.
|
"""Shut the daemon down closing all the client sessions it has.
|
||||||
|
|
|
@ -68,6 +68,7 @@ async def init(data_dir, server_conf, send_queue, recv_queue):
|
||||||
),
|
),
|
||||||
web.post("/_matrix/client/r0/user/{user_id}/filter", proxy.filter),
|
web.post("/_matrix/client/r0/user/{user_id}/filter", proxy.filter),
|
||||||
web.post("/_matrix/client/r0/search", proxy.search),
|
web.post("/_matrix/client/r0/search", proxy.search),
|
||||||
|
web.options("/_matrix/client/r0/search", proxy.search_opts),
|
||||||
])
|
])
|
||||||
app.router.add_route("*", "/" + "{proxyPath:.*}", proxy.router)
|
app.router.add_route("*", "/" + "{proxyPath:.*}", proxy.router)
|
||||||
app.on_shutdown.append(proxy.shutdown)
|
app.on_shutdown.append(proxy.shutdown)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue