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

fix: solve issue with Cache-Control header deletion #6991

Merged

Conversation

nelsonprsousa
Copy link
Contributor

@nelsonprsousa nelsonprsousa commented Oct 19, 2024

What is it?

  • Bug (kinda)

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() and fail() 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

  • My code follows the developer guidelines of this project
  • I performed a self-review of my own code
  • I added a changeset with pnpm change
  • I made corresponding changes to the Qwik docs
  • I added new tests to cover the fix / functionality

@nelsonprsousa nelsonprsousa requested a review from a team as a code owner October 19, 2024 23:28
Copy link

changeset-bot bot commented Oct 19, 2024

🦋 Changeset detected

Latest commit: d30d2f3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@builder.io/qwik-city Patch
eslint-plugin-qwik Patch
@builder.io/qwik Patch
create-qwik Patch

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

Copy link

pkg-pr-new bot commented Oct 19, 2024

Open in Stackblitz

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

Copy link
Contributor

github-actions bot commented Oct 19, 2024

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
qwik-docs ✅ Ready (View Log) Visit Preview d30d2f3

@nelsonprsousa
Copy link
Contributor Author

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

@maiieul maiieul added COMP: DX Developer Experience related issue STATUS-2: requires discussion Requires further discussion before moving forward labels Oct 27, 2024
Copy link
Member

@gioboa gioboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks @nelsonprsousa
Can you add a changeset please?(follow this tutorial)

@nelsonprsousa
Copy link
Contributor Author

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).

@gioboa
Copy link
Member

gioboa commented Nov 5, 2024

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.

@nelsonprsousa nelsonprsousa force-pushed the cache-control-headers-on-redirect branch from 4ede2d0 to 918ddd1 Compare November 5, 2024 10:36
@nelsonprsousa nelsonprsousa requested a review from a team as a code owner November 5, 2024 10:36
@nelsonprsousa nelsonprsousa force-pushed the cache-control-headers-on-redirect branch from 918ddd1 to ffee7e3 Compare November 5, 2024 10:40
@nelsonprsousa nelsonprsousa changed the title fix: remove cache-control headers handling in redirect logic fix: do not remove Cache-Control end user defined header value Nov 5, 2024
@nelsonprsousa
Copy link
Contributor Author

@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 👍

Copy link
Member

@gioboa gioboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks great to me. Can you add the fallback please?

Copy link
Member

@gioboa gioboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great @nelsonprsousa 👍

@gioboa gioboa changed the title fix: do not remove Cache-Control end user defined header value fix: solve issue with Cache-Control header deletion Nov 6, 2024
@gioboa gioboa merged commit dea36be into QwikDev:main Nov 6, 2024
19 checks passed
@github-actions github-actions bot mentioned this pull request Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
COMP: DX Developer Experience related issue STATUS-2: requires discussion Requires further discussion before moving forward
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants