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

Commit

Permalink
Remove unused OPTIONS handlers. (#8621)
Browse files Browse the repository at this point in the history
The handling of OPTIONS requests was consolidated in #7534, but the endpoint
specific handlers were not removed.
  • Loading branch information
clokep authored Oct 22, 2020
1 parent b19b63e commit 514a240
Show file tree
Hide file tree
Showing 14 changed files with 2 additions and 64 deletions.
1 change: 1 addition & 0 deletions changelog.d/8621.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove unused OPTIONS handlers.
3 changes: 1 addition & 2 deletions synapse/http/servlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ class attribute containing a pre-compiled regular expression. The automatic
on_PUT
on_POST
on_DELETE
on_OPTIONS
Automatically handles turning CodeMessageExceptions thrown by these methods
into the appropriate HTTP response.
Expand All @@ -283,7 +282,7 @@ def register(self, http_server):
if hasattr(self, "PATTERNS"):
patterns = self.PATTERNS

for method in ("GET", "PUT", "POST", "OPTIONS", "DELETE"):
for method in ("GET", "PUT", "POST", "DELETE"):
if hasattr(self, "on_%s" % (method,)):
servlet_classname = self.__class__.__name__
method_handler = getattr(self, "on_%s" % (method,))
Expand Down
3 changes: 0 additions & 3 deletions synapse/rest/client/v1/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ async def on_GET(self, request):

return 200, chunk

def on_OPTIONS(self, request):
return 200, {}


class EventRestServlet(RestServlet):
PATTERNS = client_patterns("/events/(?P<event_id>[^/]*)$", v1=True)
Expand Down
3 changes: 0 additions & 3 deletions synapse/rest/client/v1/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ def on_GET(self, request: SynapseRequest):

return 200, {"flows": flows}

def on_OPTIONS(self, request: SynapseRequest):
return 200, {}

async def on_POST(self, request: SynapseRequest):
self._address_ratelimiter.ratelimit(request.getClientIP())

Expand Down
6 changes: 0 additions & 6 deletions synapse/rest/client/v1/logout.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ def __init__(self, hs):
self._auth_handler = hs.get_auth_handler()
self._device_handler = hs.get_device_handler()

def on_OPTIONS(self, request):
return 200, {}

async def on_POST(self, request):
requester = await self.auth.get_user_by_req(request, allow_expired=True)

Expand All @@ -58,9 +55,6 @@ def __init__(self, hs):
self._auth_handler = hs.get_auth_handler()
self._device_handler = hs.get_device_handler()

def on_OPTIONS(self, request):
return 200, {}

async def on_POST(self, request):
requester = await self.auth.get_user_by_req(request, allow_expired=True)
user_id = requester.user.to_string()
Expand Down
3 changes: 0 additions & 3 deletions synapse/rest/client/v1/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ async def on_PUT(self, request, user_id):

return 200, {}

def on_OPTIONS(self, request):
return 200, {}


def register_servlets(hs, http_server):
PresenceStatusRestServlet(hs).register(http_server)
6 changes: 0 additions & 6 deletions synapse/rest/client/v1/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ async def on_PUT(self, request, user_id):

return 200, {}

def on_OPTIONS(self, request, user_id):
return 200, {}


class ProfileAvatarURLRestServlet(RestServlet):
PATTERNS = client_patterns("/profile/(?P<user_id>[^/]*)/avatar_url", v1=True)
Expand Down Expand Up @@ -118,9 +115,6 @@ async def on_PUT(self, request, user_id):

return 200, {}

def on_OPTIONS(self, request, user_id):
return 200, {}


class ProfileRestServlet(RestServlet):
PATTERNS = client_patterns("/profile/(?P<user_id>[^/]*)", v1=True)
Expand Down
3 changes: 0 additions & 3 deletions synapse/rest/client/v1/push_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ async def on_GET(self, request, path):
else:
raise UnrecognizedRequestError()

def on_OPTIONS(self, request, path):
return 200, {}

def notify_user(self, user_id):
stream_id = self.store.get_max_push_rules_stream_id()
self.notifier.on_new_event("push_rules_key", stream_id, users=[user_id])
Expand Down
9 changes: 0 additions & 9 deletions synapse/rest/client/v1/pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ async def on_GET(self, request):

return 200, {"pushers": filtered_pushers}

def on_OPTIONS(self, _):
return 200, {}


class PushersSetRestServlet(RestServlet):
PATTERNS = client_patterns("/pushers/set$", v1=True)
Expand Down Expand Up @@ -140,9 +137,6 @@ async def on_POST(self, request):

return 200, {}

def on_OPTIONS(self, _):
return 200, {}


class PushersRemoveRestServlet(RestServlet):
"""
Expand Down Expand Up @@ -182,9 +176,6 @@ async def on_GET(self, request):
)
return None

def on_OPTIONS(self, _):
return 200, {}


def register_servlets(hs, http_server):
PushersRestServlet(hs).register(http_server)
Expand Down
17 changes: 0 additions & 17 deletions synapse/rest/client/v1/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,6 @@ def __init__(self, hs):
def register(self, http_server):
PATTERNS = "/createRoom"
register_txn_path(self, PATTERNS, http_server)
# define CORS for all of /rooms in RoomCreateRestServlet for simplicity
http_server.register_paths(
"OPTIONS",
client_patterns("/rooms(?:/.*)?$", v1=True),
self.on_OPTIONS,
self.__class__.__name__,
)
# define CORS for /createRoom[/txnid]
http_server.register_paths(
"OPTIONS",
client_patterns("/createRoom(?:/.*)?$", v1=True),
self.on_OPTIONS,
self.__class__.__name__,
)

def on_PUT(self, request, txn_id):
set_tag("txn_id", txn_id)
Expand All @@ -104,9 +90,6 @@ def get_room_config(self, request):
user_supplied_config = parse_json_object_from_request(request)
return user_supplied_config

def on_OPTIONS(self, request):
return 200, {}


# TODO: Needs unit testing for generic events
class RoomStateEventRestServlet(TransactionRestServlet):
Expand Down
3 changes: 0 additions & 3 deletions synapse/rest/client/v1/voip.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ async def on_GET(self, request):
},
)

def on_OPTIONS(self, request):
return 200, {}


def register_servlets(hs, http_server):
VoipRestServlet(hs).register(http_server)
3 changes: 0 additions & 3 deletions synapse/rest/client/v2_alpha/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,6 @@ async def on_POST(self, request):

return 200, {}

def on_OPTIONS(self, _):
return 200, {}


class DeactivateAccountRestServlet(RestServlet):
PATTERNS = client_patterns("/account/deactivate$")
Expand Down
3 changes: 0 additions & 3 deletions synapse/rest/client/v2_alpha/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@ async def on_POST(self, request, stagetype):
respond_with_html(request, 200, html)
return None

def on_OPTIONS(self, _):
return 200, {}


def register_servlets(hs, http_server):
AuthRestServlet(hs).register(http_server)
3 changes: 0 additions & 3 deletions synapse/rest/client/v2_alpha/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,6 @@ async def on_POST(self, request):

return 200, return_dict

def on_OPTIONS(self, _):
return 200, {}

async def _do_appservice_registration(self, username, as_token, body):
user_id = await self.registration_handler.appservice_register(
username, as_token
Expand Down

0 comments on commit 514a240

Please sign in to comment.