_header_x now defaults to empty string

Prior to this a request to e.g. https://latest.datasette.io/fixtures/magic_parameters
which did not include a User-Agent header would trigger a 500 error.
json-post
Simon Willison 2020-06-30 15:00:17 -07:00
rodzic 2115d7e345
commit 9ac6292614
2 zmienionych plików z 2 dodań i 1 usunięć

Wyświetl plik

@ -8,7 +8,7 @@ import time
def header(key, request):
key = key.replace("_", "-").encode("utf-8")
headers_dict = dict(request.scope["headers"])
return headers_dict[key].decode("utf-8")
return headers_dict.get(key, b"").decode("utf-8")
def actor(key, request):

Wyświetl plik

@ -186,6 +186,7 @@ def magic_parameters_client():
[
("_actor_id", "root"),
("_header_host", "localhost"),
("_header_not_a_thing", ""),
("_cookie_foo", "bar"),
("_now_epoch", r"^\d+$"),
("_now_date_utc", r"^\d{4}-\d{2}-\d{2}$"),