Skip to content

Conversation

@cburroughs
Copy link
Contributor

RFC 9111 §3 - Storing Responses in Caches, describes the conditions under which a cache may store a response. Notably all final (aka not 1xx) status codes are potentially cacheable, subject to the other listed conditions.

In brief a response must have either an explicit header (such as a max-age directive) OR have a heuristically cacheable status code. Which status codes are heuristically cacheable is helpfully summarized in RFC 9110 §15.1 - Overview of Status Codes: 200, 203, 204, 206, 300, 301, 308, 404, 405, 410, 414, and 501)

CacheController has historically maintained a more conservative list of cacheable_status_codes that are a subset of the heuristically cacheable ones.

This diff makes related changes:

  • Temporary redirects are now cached by default. Besides being correct in the general case, temporary redirects are used by several Python Registries as discussed in HTTP 302 Found responses with Cache Headers not being cached #384.
  • Because temporary redirects are not heuristically cacheable, add a check to only cache them when explicit headers are present. This means that regardless of which status_codes are passed to CacheController, the HTTP specification is still followed.
  • As defensive future proofing, make sure the response is final before much else is done.

fixes #384

RFC 9111 §3 - Storing Responses in Caches, describes the conditions
under which a cache may store a response.  Notably all final (aka not
1xx) status codes are *potentially* cacheable, subject to the other
listed conditions.

In brief a response must have either an explicit header (such as a
`max-age` directive) OR have a heuristically cacheable status code.
Which status codes are heuristically cacheable is helpfully summarized
in RFC 9110 §15.1 - Overview of Status Codes: 200, 203, 204, 206,
300, 301, 308, 404, 405, 410, 414, and 501)

CacheController has historically maintained a more conservative list
of cacheable_status_codes that are a subset of the heuristically
cacheable ones.

This diff makes related changes:
 * Temporary redirects are now cached by default.  Besides being
 correct in the general case, temporary redirects are used by several
 Python Registries as discussed in psf#384.
 * Because temporary redirects are not heuristically cacheable, add a
 check to only cache them when explicit headers are present.  This
 means that regardless of which status_codes are passed to
 CacheController, the HTTP specification is still followed.
 * As defensive future proofing, make sure the response is
 final before much else is done.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP 302 Found responses with Cache Headers not being cached

1 participant