Skip to content

@cache() with no directives sends an empty Cache-Control header #363

Description

@allen0099

Found during the docs audit (#361).

_build_cache_control returns "" when no directive is set, and _with_cache_control (fastapi_cachex/cache.py:1145) sets the header anyway, so a plain @cache() answers with an empty header:

@app.get("/e")
@cache()
async def e(): ...
# response.headers["cache-control"] == ""

An empty Cache-Control is valid to ignore but useless, and it replaces any Cache-Control the handler set itself. Expected: omit the header when there are no directives (and keep the handler's own header, if the current code would otherwise overwrite it; check which applies). Add a test.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghttp-cacheThe @cache decorator, cache keys and Cache-Control handling

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions