Closed nelsonprsousa closed 2 weeks ago
Latest commit: d30d2f37752921be5e69c421c814de246a4d3d04
The changes in this PR will be included in the next version bump.
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
npm i https://pkg.pr.new/@builder.io/qwik@6991
npm i https://pkg.pr.new/@builder.io/qwik-city@6991
npm i https://pkg.pr.new/eslint-plugin-qwik@6991
npm i https://pkg.pr.new/create-qwik@6991
commit: d30d2f3
Name | Status | Preview | Last Commit |
---|---|---|---|
qwik-docs | β Ready (View Log) | Visit Preview | d30d2f37752921be5e69c421c814de246a4d3d04 |
After a more in-depth analysis, I found that we currently have three methods that are hard deleting user-defined Cache-Control
headers:
redirect
error
fail
In my opinion, at least redirect
and error
should not enforce this rule. For HTTP 301, 302, 307, 308, and possibly other 3xx status codes, it should be the user's responsibility to define the cache control. Additionally, when we do something like throw error(HttpStatusCode.NOT_FOUND, 'Not Found');
(e.g., when the id
in a route like url.com/:id
does not exist), that response should be cacheable. This means we should remove the hardcoded rule from the error
handler as well.
As for the fail
handler, I donβt have a strong opinion. It may be used more in the 5xx range, such as for internal server errors, where invalidating the cache could be the right approach.
Looking forward to your feedback @wmertens @thejackshelton @maiieul @mhevery
Nice, thanks @nelsonprsousa Can you add a changeset please?(follow this tutorial)
Sure, I can.
What do you think about the other handlers that are actually doing the same thing? Particularly error
?
fail
I am tempted to leave it as is (even though I still think it is quite a bold move from a framework to perform this kind of operations).
I think is not correct to change that header internally because the end user needs to have the ability to manage it. So I think we need to be transparent on that and keep the end user one and we can add a fallback to preserve the actual behavior.
@gioboa I removed the hard code removal of the Cache-Control header from qwik-city as agreed π
Also added a changeset.
LMK if everything's ok π
What is it?
Description
Currently, it is impossible to define a Cache-Control header using the
request.cacheControl
on any method that takes a request event other than success (HTTP 200). Looks like qwik-city, internally, deletes whatever is defined.I am not entirely sure about the
error()
andfail()
handlers, which are also forcing the removal of the header. I'd say that engineers could potentially decide to cache 404s, for example, and the framework should not enforce this kind of rules. However, I am not sure about this premise for 4xx or 5xx.Redirects (HTTP 301, HTTP 302, HTTP 307, HTTP 308, at least) should be totally configurable by software engineers.
Checklist
pnpm change