diff --git a/datasette/app.py b/datasette/app.py index 4552d9d4..28b5e857 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -36,6 +36,7 @@ from .utils import ( from .utils.asgi import ( AsgiLifespan, asgi_static, + asgi_send, asgi_send_html, asgi_send_json, asgi_send_redirect, @@ -131,14 +132,7 @@ DEFAULT_CONFIG = {option.name: option.default for option in CONFIG_OPTIONS} async def favicon(scope, receive, send): - await send( - { - "type": "http.response.start", - "status": 200, - "headers": [[b"content-type", b"text/plain"]], - } - ) - await send({"type": "http.response.body", "body": b""}) + await asgi_send(send, "", 200) class Datasette: diff --git a/datasette/utils/asgi.py b/datasette/utils/asgi.py index be53627f..ac7d62a4 100644 --- a/datasette/utils/asgi.py +++ b/datasette/utils/asgi.py @@ -213,12 +213,13 @@ async def asgi_send_redirect(send, location, status=302): ) -async def asgi_send(send, content, status, headers, content_type="text/plain"): +async def asgi_send(send, content, status, headers=None, content_type="text/plain"): await asgi_start(send, status, headers, content_type) await send({"type": "http.response.body", "body": content.encode("utf8")}) -async def asgi_start(send, status, headers, content_type="text/plain"): +async def asgi_start(send, status, headers=None, content_type="text/plain"): + headers = headers or {} # Remove any existing content-type header headers = dict([(k, v) for k, v in headers.items() if k.lower() != "content-type"]) headers["content-type"] = content_type