-
Notifications
You must be signed in to change notification settings - Fork 168
Add support for 304 responses with If-None-Match (Etag) and If-Modified-Since #8142
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
Open
pedro-psb
wants to merge
1
commit into
pulp:main
Choose a base branch
from
pedro-psb:add-if-modified-since-content-app2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+383
−26
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added `ETag`/`If-None-Match` and `Last-Modified`/`If-Modified-Since` (`304 Not Modified`) support on content-app responses so edge caches can revalidate without re-downloading. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # CDN Caching | ||
|
|
||
| Pulp's content app implements some behavior to help with external caching processes. | ||
|
|
||
| ## Cache Validation | ||
|
|
||
| For most requests, the Content App returns [`Last-Modified`][last-modified] and [`ETag`][etag] headers for the requested resource; the ETag is usually a digest. | ||
| [Shared caches][cache-types], such as CDNs, and private caches, such as clients, can use these validators to decide whether to serve a stored response or request the resource from Pulp again. | ||
| To avoid resources being served to unauthorized parties, Pulp uses [`Cache-Control`][cache-control] directives to enforce that: | ||
| (a) cache entities always ask for validation before serving cached content; | ||
| (b) only Private Caches can store certain sensitive responses (e.g., signed URLs). | ||
|
|
||
| A typical flow looks like: | ||
|
|
||
| 1. A client requests a resource through a shared cache, such as a CDN. | ||
| If the cache has no copy, it forwards the request to Pulp. | ||
| 2. Pulp returns the content with `Cache-Control: public, max-age=0, must-revalidate`, `Last-Modified`, and `ETag`. | ||
| The shared cache stores the response and its validators. | ||
| 3. On a later request, the shared cache must revalidate its stored response with Pulp. | ||
| It sends [`If-None-Match`][if-none-match] with the stored ETag, [`If-Modified-Since`][if-modified-since] with the stored date, or both. | ||
| When both are present, Pulp checks `If-None-Match`. | ||
| 4. If the content is unchanged, Pulp returns `304 Not Modified` without a body. | ||
| The shared cache serves its stored content to the client. | ||
| If the content changed, Pulp returns the full response with updated validators, and the cache replaces its stored copy. | ||
|
|
||
| ### Known limitations | ||
|
|
||
| Pulp does not track the content that a distribution serves over time. | ||
| It infers `Last-Modified` based on the assumption that a distribution serves repository versions monotonically. | ||
| If that's not true, Pulp might tell the cache entity that a resource has not changed when it has. | ||
|
|
||
| The `ETag`/`If-None-Match` mechanism is unaffected by this limitation. | ||
|
|
||
| [cache-types]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Caching#types_of_caches | ||
| [last-modified]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Last-Modified | ||
| [etag]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag | ||
| [cache-control]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control | ||
| [if-none-match]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/If-None-Match | ||
| [if-modified-since]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/If-Modified-Since |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added these
[SRV-XYZ]"label comments" because there are 15 different return cases in the match-and-stream (without counting the serve vs stream variations), and if you wanna think about it, or take notes about this flow, it's a bit hard. Of course AI helps a lot, but still, naming things help us humans understand and manipulate them.I'm fine with removing if this feels too personal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does SRV even stand for? Serve? The problem with acronyms is that no one ever knows what they mean. I would just choose a simple 1-2 word title to label the comments if that will be helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, serve hehe I kinda find this helpful to myself, but I can see it might just cause confusion to anyone else. I'll drop it.