Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/fastapi_redis_cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ async def inner_wrapper(*args, **kwargs):
create_response_directly = not response
if create_response_directly:
response = Response()
# The response may get created with a 'content-length' header equal to 0. Of course, if the `func` function does return something, this header becomes a mismatch with the actual content.
# uvicorn is sensible to it and then raises a 'RuntimeError: Response content longer than Content-Length' exception.
# As a workaround, the 'content-length' header is cleared from the response.headers if it exists
if "content-length" in response.headers.keys():
del response.headers["content-length"]
redis_cache = FastApiRedisCache()
if redis_cache.not_connected or redis_cache.request_is_not_cacheable(request):
# if the redis client is not connected or request is not cacheable, no caching behavior is performed.
Expand Down