Cleaned up favicon()

This commit is contained in:
Simon Willison 2019-06-23 14:55:19 -07:00
commit 620f0aa4f8
2 changed files with 5 additions and 10 deletions

View file

@ -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:

View file

@ -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