Correct syntax for link headers, closes #2470

This commit is contained in:
Simon Willison 2025-03-09 20:05:43 -05:00
commit 333f786cb0
6 changed files with 7 additions and 7 deletions

View file

@ -158,7 +158,7 @@ class BaseView:
template_context["alternate_url_json"] = alternate_url_json
headers.update(
{
"Link": '{}; rel="alternate"; type="application/json+datasette"'.format(
"Link": '<{}>; rel="alternate"; type="application/json+datasette"'.format(
alternate_url_json
)
}

View file

@ -181,7 +181,7 @@ class DatabaseView(View):
view_name="database",
),
headers={
"Link": '{}; rel="alternate"; type="application/json+datasette"'.format(
"Link": '<{}>; rel="alternate"; type="application/json+datasette"'.format(
alternate_url_json
)
},
@ -630,7 +630,7 @@ class QueryView(View):
data = {}
headers.update(
{
"Link": '{}; rel="alternate"; type="application/json+datasette"'.format(
"Link": '<{}>; rel="alternate"; type="application/json+datasette"'.format(
alternate_url_json
)
}

View file

@ -894,7 +894,7 @@ async def table_view_traced(datasette, request):
)
headers.update(
{
"Link": '{}; rel="alternate"; type="application/json+datasette"'.format(
"Link": '<{}>; rel="alternate"; type="application/json+datasette"'.format(
alternate_url_json
)
}

View file

@ -457,7 +457,7 @@ You can find this near the top of the source code of those pages, looking like t
The JSON URL is also made available in a ``Link`` HTTP header for the page::
Link: https://latest.datasette.io/fixtures/sortable.json; rel="alternate"; type="application/json+datasette"
Link: <https://latest.datasette.io/fixtures/sortable.json>; rel="alternate"; type="application/json+datasette"
.. _json_api_cors:

View file

@ -433,7 +433,7 @@ def test_canned_write_custom_template(canned_write_client):
)
assert (
response.headers["link"]
== 'http://localhost/data/update_name.json; rel="alternate"; type="application/json+datasette"'
== '<http://localhost/data/update_name.json>; rel="alternate"; type="application/json+datasette"'
)

View file

@ -1040,7 +1040,7 @@ async def test_alternate_url_json(ds_client, path, expected):
response = await ds_client.get(path)
assert response.status_code == 200
link = response.headers["link"]
assert link == '{}; rel="alternate"; type="application/json+datasette"'.format(
assert link == '<{}>; rel="alternate"; type="application/json+datasette"'.format(
expected
)
assert (