From e54be85aba48201b0f1c061c892bdc380efb754d Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Tue, 23 Jan 2024 08:42:18 +0100 Subject: [PATCH] Check if "extensions" in scope before checking the extension (#2438) --- starlette/responses.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starlette/responses.py b/starlette/responses.py index 9d259a075..4fb7697b8 100644 --- a/starlette/responses.py +++ b/starlette/responses.py @@ -337,7 +337,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: ) if scope["method"].upper() == "HEAD": await send({"type": "http.response.body", "body": b"", "more_body": False}) - elif "http.response.pathsend" in scope["extensions"]: + elif "extensions" in scope and "http.response.pathsend" in scope["extensions"]: await send({"type": "http.response.pathsend", "path": str(self.path)}) else: async with await anyio.open_file(self.path, mode="rb") as file: