-
Notifications
You must be signed in to change notification settings - Fork 103
server: omit Vary: Accept-Encoding when NoCompression extension is set #1629
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
NeonPhantom123
wants to merge
10
commits into
oxidecomputer:main
Choose a base branch
from
NeonPhantom123:fix/no-compression-vary-header
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.
Open
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2ade744
server: omit Vary: Accept-Encoding when NoCompression extension is set
NeonPhantom123 3186313
compression: test that NoCompression suppresses should_compress_response
NeonPhantom123 8356f85
address review: update comments, move assert to integration tests
NeonPhantom123 97654da
fix: import NoCompression in server.rs
NeonPhantom123 fc91a5e
fix: use super:: for NoCompression import to match file convention
NeonPhantom123 fe3c71f
fix: remove unit test, add Vary asserts to integration tests
NeonPhantom123 ed17e94
fix: remove unit test from compression.rs
NeonPhantom123 aa55d9c
fix: restore ProbeRegistration import and fix extra brace in compress…
NeonPhantom123 da71f20
fix: correct closing brace indentation in compression.rs
NeonPhantom123 9e942b9
fix: sort NoCompression import alphabetically per cargo fmt
NeonPhantom123 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
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 |
|---|---|---|
|
|
@@ -988,35 +988,37 @@ async fn http_request_handle<C: ServerContext>( | |
| } | ||
| } | ||
| } | ||
| }; | ||
| }; | ||
|
|
||
| if matches!(server.config.compression, CompressionConfig::Gzip) | ||
| && is_compressible_content_type(response.headers()) | ||
| { | ||
| // Add Vary: Accept-Encoding header for all compressible content | ||
| // types. This needs to be there even if the response ends up not being | ||
| // compressed because it tells caches (like browsers and CDNs) that the | ||
| // response content depends on the value of the Accept-Encoding header. | ||
| // Without this, a cache might mistakenly serve a compressed response to | ||
| // a client that cannot decompress it, or serve an uncompressed response | ||
| // to a client that could have benefited from compression. | ||
| if matches!(server.config.compression, CompressionConfig::Gzip) | ||
| && is_compressible_content_type(response.headers()) | ||
| { | ||
| if should_compress_response( | ||
| &method, | ||
| &request_headers, | ||
| response.status(), | ||
| response.headers(), | ||
| response.extensions(), | ||
| ) { | ||
| // Add Vary: Accept-Encoding and compress. The Vary header is added | ||
| // here so caches know they must not serve a compressed response to | ||
| // a client that didn't accept it. | ||
| add_vary_header(response.headers_mut()); | ||
| response = apply_gzip_compression(response); | ||
| } else if response.extensions().get::<NoCompression>().is_none() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // Add Vary: Accept-Encoding for compressible responses that are | ||
| // skipped this time (e.g. body too small, wrong method, partial | ||
| // content) but that could be compressed for a different request. | ||
| // Omit Vary when NoCompression is set because that response will | ||
| // never be compressed regardless of Accept-Encoding. | ||
| add_vary_header(response.headers_mut()); | ||
|
|
||
| if should_compress_response( | ||
| &method, | ||
| &request_headers, | ||
| response.status(), | ||
| response.headers(), | ||
| response.extensions(), | ||
| ) { | ||
| response = apply_gzip_compression(response); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| response.headers_mut().insert( | ||
| HEADER_REQUEST_ID, | ||
| http::header::HeaderValue::from_str(&request_id).unwrap(), | ||
| ); | ||
| response.headers_mut().insert( | ||
| HEADER_REQUEST_ID, | ||
| http::header::HeaderValue::from_str(&request_id).unwrap(), | ||
| ); | ||
| Ok(response) | ||
| } | ||
|
|
||
|
|
||
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 think you can get rid of this test and add these asserts to the integration tests instead.