Support OPTIONS without 500, closes #1001

pull/1000/head
Simon Willison 2020-10-08 18:43:53 -07:00
rodzic 703439bdc3
commit 7249ac5ca0
2 zmienionych plików z 9 dodań i 0 usunięć

Wyświetl plik

@ -110,6 +110,9 @@ class BaseView:
def database_color(self, database):
return "ff0000"
async def options(self, request, *args, **kwargs):
return Response.text("Method not allowed", status=405)
async def dispatch_request(self, request, *args, **kwargs):
handler = getattr(self, request.method.lower(), None)
return await handler(request, *args, **kwargs)

Wyświetl plik

@ -52,6 +52,12 @@ def test_http_head(app_client):
assert response.status == 200
def test_homepage_options(app_client):
response = app_client.get("/", method="OPTIONS")
assert response.status == 405
assert response.text == "Method not allowed"
def test_favicon(app_client):
response = app_client.get("/favicon.ico")
assert response.status == 200