diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a27b676..04839a1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,8 @@ Using the following categories, list your changes in this order: ## [Unreleased] -- Nothing (yet)! +- Prevent responses with no body from creating a warning by providing Django an empty async iterable as the file content. +- Force Django>=3.2 to use async file responses if possible, regardless of whether the middleware is run in sync or async mode. ## [1.0.0] - 2024-05-08 diff --git a/src/servestatic/middleware.py b/src/servestatic/middleware.py index 6c5c7dbe..f693106a 100644 --- a/src/servestatic/middleware.py +++ b/src/servestatic/middleware.py @@ -162,7 +162,7 @@ def __call__(self, request): if iscoroutinefunction(self.get_response): return self.acall(request) - # Force Django >= 3.2 use async file responses when using ASGI, even + # Allow Django >= 3.2 to use async file responses when running via ASGI, even # if Django forces this middleware to run synchronously if django.VERSION >= (3, 2): return asyncio.run(self.acall(request)) @@ -171,8 +171,8 @@ def __call__(self, request): return self.call(request) def call(self, request): - """If the URL contains a static file, serve it. - Otherwise, continue to the next middleware.""" + """If the URL contains a static file, serve it. Otherwise, continue to the next + middleware.""" if self.autorefresh: static_file = self.find_file(request.path_info) else: @@ -184,8 +184,8 @@ def call(self, request): return self.get_response(request) async def acall(self, request): - """If the URL contains a static file, serve it. - Otherwise, continue to the next middleware.""" + """If the URL contains a static file, serve it. Otherwise, continue to the next + middleware.""" if self.autorefresh and hasattr(asyncio, "to_thread"): # Use a thread while searching disk for files on Python 3.9+ static_file = await asyncio.to_thread(self.find_file, request.path_info)