Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware does not cache 201 status code #118

Open
ericnorris opened this issue Oct 16, 2019 · 1 comment
Open

Middleware does not cache 201 status code #118

ericnorris opened this issue Oct 16, 2019 · 1 comment
Labels

Comments

@ericnorris
Copy link

ericnorris commented Oct 16, 2019

Per:

protected $statusAccepted = [
200 => 200,
203 => 203,
204 => 204,
300 => 300,
301 => 301,
404 => 404,
405 => 405,
410 => 410,
414 => 414,
418 => 418,
501 => 501,
];

and:

if (!isset($this->statusAccepted[$response->getStatusCode()])) {
// Don't cache it
return;
}

...the caching middleware does not cache a 201 response. I believe this is not compliant with the RFC on caching, and should in fact be cached if the response contains the appropriate caching headers.

https://tools.ietf.org/html/rfc7231#section-6.1 states that:

Responses with status codes that are defined as cacheable by default
(e.g., 200, 203, 204, 206, 300, 301, 404, 405, 410, 414, and 501 in
this specification) can be reused by a cache with heuristic
expiration unless otherwise indicated by the method definition or
explicit cache controls [RFC7234]; all other status codes are not
cacheable by default.

If I am reading this correctly, that does not mean that status codes in this list must not be cached, but that they must not be cached by default. A status code not in this list (e.g. 201) is still cacheable if there are appropriate Cache-Control headers, as indicated in https://tools.ietf.org/html/rfc7234#section-3:

A cache MUST NOT store a response to any request, unless:
...
the response either:
...

  • contains a Cache Control Extension (see Section 5.2.3) that allows it to be cached, or

In my particular case, I am receiving a 201 with a header of Cache-Control: public, max-age=60, s-maxage=60, and expect it to be cached.

@Kevinrob
Copy link
Owner

I thing that this is right. We should change the logic.

@Kevinrob Kevinrob added the bug label Dec 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants