Remove unused OPTIONS handlers. (#8621)

The handling of OPTIONS requests was consolidated in #7534, but the endpoint
specific handlers were not removed.
This commit is contained in:
Patrick Cloke 2020-10-22 08:35:55 -04:00 committed by GitHub
parent b19b63e6b4
commit 514a240aed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 2 additions and 64 deletions

1
changelog.d/8621.misc Normal file
View File

@ -0,0 +1 @@
Remove unused OPTIONS handlers.

View File

@ -272,7 +272,6 @@ class RestServlet:
on_PUT on_PUT
on_POST on_POST
on_DELETE on_DELETE
on_OPTIONS
Automatically handles turning CodeMessageExceptions thrown by these methods Automatically handles turning CodeMessageExceptions thrown by these methods
into the appropriate HTTP response. into the appropriate HTTP response.
@ -283,7 +282,7 @@ class RestServlet:
if hasattr(self, "PATTERNS"): if hasattr(self, "PATTERNS"):
patterns = 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,)): if hasattr(self, "on_%s" % (method,)):
servlet_classname = self.__class__.__name__ servlet_classname = self.__class__.__name__
method_handler = getattr(self, "on_%s" % (method,)) method_handler = getattr(self, "on_%s" % (method,))

View File

@ -67,9 +67,6 @@ class EventStreamRestServlet(RestServlet):
return 200, chunk return 200, chunk
def on_OPTIONS(self, request):
return 200, {}
class EventRestServlet(RestServlet): class EventRestServlet(RestServlet):
PATTERNS = client_patterns("/events/(?P<event_id>[^/]*)$", v1=True) PATTERNS = client_patterns("/events/(?P<event_id>[^/]*)$", v1=True)

View File

@ -114,9 +114,6 @@ class LoginRestServlet(RestServlet):
return 200, {"flows": flows} return 200, {"flows": flows}
def on_OPTIONS(self, request: SynapseRequest):
return 200, {}
async def on_POST(self, request: SynapseRequest): async def on_POST(self, request: SynapseRequest):
self._address_ratelimiter.ratelimit(request.getClientIP()) self._address_ratelimiter.ratelimit(request.getClientIP())

View File

@ -30,9 +30,6 @@ class LogoutRestServlet(RestServlet):
self._auth_handler = hs.get_auth_handler() self._auth_handler = hs.get_auth_handler()
self._device_handler = hs.get_device_handler() self._device_handler = hs.get_device_handler()
def on_OPTIONS(self, request):
return 200, {}
async def on_POST(self, request): async def on_POST(self, request):
requester = await self.auth.get_user_by_req(request, allow_expired=True) requester = await self.auth.get_user_by_req(request, allow_expired=True)
@ -58,9 +55,6 @@ class LogoutAllRestServlet(RestServlet):
self._auth_handler = hs.get_auth_handler() self._auth_handler = hs.get_auth_handler()
self._device_handler = hs.get_device_handler() self._device_handler = hs.get_device_handler()
def on_OPTIONS(self, request):
return 200, {}
async def on_POST(self, request): async def on_POST(self, request):
requester = await self.auth.get_user_by_req(request, allow_expired=True) requester = await self.auth.get_user_by_req(request, allow_expired=True)
user_id = requester.user.to_string() user_id = requester.user.to_string()

View File

@ -86,9 +86,6 @@ class PresenceStatusRestServlet(RestServlet):
return 200, {} return 200, {}
def on_OPTIONS(self, request):
return 200, {}
def register_servlets(hs, http_server): def register_servlets(hs, http_server):
PresenceStatusRestServlet(hs).register(http_server) PresenceStatusRestServlet(hs).register(http_server)

View File

@ -67,9 +67,6 @@ class ProfileDisplaynameRestServlet(RestServlet):
return 200, {} return 200, {}
def on_OPTIONS(self, request, user_id):
return 200, {}
class ProfileAvatarURLRestServlet(RestServlet): class ProfileAvatarURLRestServlet(RestServlet):
PATTERNS = client_patterns("/profile/(?P<user_id>[^/]*)/avatar_url", v1=True) PATTERNS = client_patterns("/profile/(?P<user_id>[^/]*)/avatar_url", v1=True)
@ -118,9 +115,6 @@ class ProfileAvatarURLRestServlet(RestServlet):
return 200, {} return 200, {}
def on_OPTIONS(self, request, user_id):
return 200, {}
class ProfileRestServlet(RestServlet): class ProfileRestServlet(RestServlet):
PATTERNS = client_patterns("/profile/(?P<user_id>[^/]*)", v1=True) PATTERNS = client_patterns("/profile/(?P<user_id>[^/]*)", v1=True)

View File

@ -155,9 +155,6 @@ class PushRuleRestServlet(RestServlet):
else: else:
raise UnrecognizedRequestError() raise UnrecognizedRequestError()
def on_OPTIONS(self, request, path):
return 200, {}
def notify_user(self, user_id): def notify_user(self, user_id):
stream_id = self.store.get_max_push_rules_stream_id() stream_id = self.store.get_max_push_rules_stream_id()
self.notifier.on_new_event("push_rules_key", stream_id, users=[user_id]) self.notifier.on_new_event("push_rules_key", stream_id, users=[user_id])

View File

@ -60,9 +60,6 @@ class PushersRestServlet(RestServlet):
return 200, {"pushers": filtered_pushers} return 200, {"pushers": filtered_pushers}
def on_OPTIONS(self, _):
return 200, {}
class PushersSetRestServlet(RestServlet): class PushersSetRestServlet(RestServlet):
PATTERNS = client_patterns("/pushers/set$", v1=True) PATTERNS = client_patterns("/pushers/set$", v1=True)
@ -140,9 +137,6 @@ class PushersSetRestServlet(RestServlet):
return 200, {} return 200, {}
def on_OPTIONS(self, _):
return 200, {}
class PushersRemoveRestServlet(RestServlet): class PushersRemoveRestServlet(RestServlet):
""" """
@ -182,9 +176,6 @@ class PushersRemoveRestServlet(RestServlet):
) )
return None return None
def on_OPTIONS(self, _):
return 200, {}
def register_servlets(hs, http_server): def register_servlets(hs, http_server):
PushersRestServlet(hs).register(http_server) PushersRestServlet(hs).register(http_server)

View File

@ -72,20 +72,6 @@ class RoomCreateRestServlet(TransactionRestServlet):
def register(self, http_server): def register(self, http_server):
PATTERNS = "/createRoom" PATTERNS = "/createRoom"
register_txn_path(self, PATTERNS, http_server) 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): def on_PUT(self, request, txn_id):
set_tag("txn_id", txn_id) set_tag("txn_id", txn_id)
@ -104,9 +90,6 @@ class RoomCreateRestServlet(TransactionRestServlet):
user_supplied_config = parse_json_object_from_request(request) user_supplied_config = parse_json_object_from_request(request)
return user_supplied_config return user_supplied_config
def on_OPTIONS(self, request):
return 200, {}
# TODO: Needs unit testing for generic events # TODO: Needs unit testing for generic events
class RoomStateEventRestServlet(TransactionRestServlet): class RoomStateEventRestServlet(TransactionRestServlet):

View File

@ -69,9 +69,6 @@ class VoipRestServlet(RestServlet):
}, },
) )
def on_OPTIONS(self, request):
return 200, {}
def register_servlets(hs, http_server): def register_servlets(hs, http_server):
VoipRestServlet(hs).register(http_server) VoipRestServlet(hs).register(http_server)

View File

@ -268,9 +268,6 @@ class PasswordRestServlet(RestServlet):
return 200, {} return 200, {}
def on_OPTIONS(self, _):
return 200, {}
class DeactivateAccountRestServlet(RestServlet): class DeactivateAccountRestServlet(RestServlet):
PATTERNS = client_patterns("/account/deactivate$") PATTERNS = client_patterns("/account/deactivate$")

View File

@ -176,9 +176,6 @@ class AuthRestServlet(RestServlet):
respond_with_html(request, 200, html) respond_with_html(request, 200, html)
return None return None
def on_OPTIONS(self, _):
return 200, {}
def register_servlets(hs, http_server): def register_servlets(hs, http_server):
AuthRestServlet(hs).register(http_server) AuthRestServlet(hs).register(http_server)

View File

@ -642,9 +642,6 @@ class RegisterRestServlet(RestServlet):
return 200, return_dict return 200, return_dict
def on_OPTIONS(self, _):
return 200, {}
async def _do_appservice_registration(self, username, as_token, body): async def _do_appservice_registration(self, username, as_token, body):
user_id = await self.registration_handler.appservice_register( user_id = await self.registration_handler.appservice_register(
username, as_token username, as_token