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

Commit

Permalink
Return JSON errors for unknown resources under /matrix/client. (#11602)
Browse files Browse the repository at this point in the history
Instead of returning 404 errors with HTML bodies when an unknown
prefix was requested (e.g. /matrix/client/v1 before Synapse v1.49.0).
  • Loading branch information
clokep authored Dec 20, 2021
1 parent 7a7ca8f commit 3e0cfd4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog.d/11602.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a long-standing bug that some unknown endpoints would return HTML error pages instead of JSON `M_UNRECOGNIZED` errors.
9 changes: 2 additions & 7 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import synapse.config.logger
from synapse import events
from synapse.api.urls import (
CLIENT_API_PREFIX,
FEDERATION_PREFIX,
LEGACY_MEDIA_PREFIX,
MEDIA_R0_PREFIX,
Expand Down Expand Up @@ -192,13 +193,7 @@ def _configure_named_resource(

resources.update(
{
"/_matrix/client/api/v1": client_resource,
"/_matrix/client/r0": client_resource,
"/_matrix/client/v1": client_resource,
"/_matrix/client/v3": client_resource,
"/_matrix/client/unstable": client_resource,
"/_matrix/client/v2_alpha": client_resource,
"/_matrix/client/versions": client_resource,
CLIENT_API_PREFIX: client_resource,
"/.well-known": well_known_resource(self),
"/_synapse/admin": AdminRestResource(self),
**build_synapse_client_resource_tree(self),
Expand Down
6 changes: 3 additions & 3 deletions synapse/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ class RootRedirect(resource.Resource):
"""Redirects the root '/' path to another path."""

def __init__(self, path: str):
resource.Resource.__init__(self)
super().__init__()
self.url = path

def render_GET(self, request: Request) -> bytes:
Expand All @@ -539,7 +539,7 @@ def render_GET(self, request: Request) -> bytes:
def getChild(self, name: str, request: Request) -> resource.Resource:
if len(name) == 0:
return self # select ourselves as the child to render
return resource.Resource.getChild(self, name, request)
return super().getChild(name, request)


class OptionsResource(resource.Resource):
Expand All @@ -556,7 +556,7 @@ def render_OPTIONS(self, request: Request) -> bytes:
def getChildWithDefault(self, path: str, request: Request) -> resource.Resource:
if request.method == b"OPTIONS":
return self # select ourselves as the child to render
return resource.Resource.getChildWithDefault(self, path, request)
return super().getChildWithDefault(path, request)


class RootOptionsRedirectResource(OptionsResource, RootRedirect):
Expand Down

0 comments on commit 3e0cfd4

Please sign in to comment.