mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Fix for OPTIONS request against /db, closes #1100
This commit is contained in:
parent
daae35be46
commit
a45a3dff3e
3 changed files with 30 additions and 1 deletions
|
|
@ -99,6 +99,29 @@ class TestClient:
|
||||||
content_type=content_type,
|
content_type=content_type,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@async_to_sync
|
||||||
|
async def request(
|
||||||
|
self,
|
||||||
|
path,
|
||||||
|
allow_redirects=True,
|
||||||
|
redirect_count=0,
|
||||||
|
method="GET",
|
||||||
|
cookies=None,
|
||||||
|
headers=None,
|
||||||
|
post_body=None,
|
||||||
|
content_type=None,
|
||||||
|
):
|
||||||
|
return await self._request(
|
||||||
|
path,
|
||||||
|
allow_redirects=allow_redirects,
|
||||||
|
redirect_count=redirect_count,
|
||||||
|
method=method,
|
||||||
|
cookies=cookies,
|
||||||
|
headers=headers,
|
||||||
|
post_body=post_body,
|
||||||
|
content_type=content_type,
|
||||||
|
)
|
||||||
|
|
||||||
async def _request(
|
async def _request(
|
||||||
self,
|
self,
|
||||||
path,
|
path,
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ class DataView(BaseView):
|
||||||
name = ""
|
name = ""
|
||||||
re_named_parameter = re.compile(":([a-zA-Z0-9_]+)")
|
re_named_parameter = re.compile(":([a-zA-Z0-9_]+)")
|
||||||
|
|
||||||
def options(self, request, *args, **kwargs):
|
async def options(self, request, *args, **kwargs):
|
||||||
r = Response.text("ok")
|
r = Response.text("ok")
|
||||||
if self.ds.cors:
|
if self.ds.cors:
|
||||||
r.headers["Access-Control-Allow-Origin"] = "*"
|
r.headers["Access-Control-Allow-Origin"] = "*"
|
||||||
|
|
|
||||||
|
|
@ -1961,3 +1961,9 @@ async def test_generated_columns_are_visible_in_datasette(app_client):
|
||||||
"string": "This is a string",
|
"string": "This is a string",
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_http_options_request(app_client):
|
||||||
|
response = app_client.request("/fixtures", method="OPTIONS")
|
||||||
|
assert response.status == 200
|
||||||
|
assert response.text == "ok"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue