From d9c3254945c095d4fabb68faee389dbbc5d546d4 Mon Sep 17 00:00:00 2001 From: Joe Cheng Date: Tue, 27 Aug 2024 12:23:58 -0700 Subject: [PATCH] Fix KeyError when serving static files Not sure what is triggering this but it's happening intermittently for both @cpsievert and myself. Not sure why Content-Type would ever be missing, much less intermittently. --- shiny/http_staticfiles.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shiny/http_staticfiles.py b/shiny/http_staticfiles.py index 57950c223..b45ccd1fc 100644 --- a/shiny/http_staticfiles.py +++ b/shiny/http_staticfiles.py @@ -43,7 +43,7 @@ def file_response( **kwargs: Any, ) -> starlette.responses.Response: resp = super().file_response(full_path, *args, **kwargs) - if resp.headers["content-type"].startswith("text/plain"): + if resp.headers.get("content-type", "").startswith("text/plain"): correct_type = _utils.guess_mime_type(full_path) resp.headers["content-type"] = ( f"{correct_type}; charset={resp.charset}"