-
Notifications
You must be signed in to change notification settings - Fork 271
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
add support for setting vary header in plugins #1660
Merged
Merged
Conversation
This file contains 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 changes the behaviour of the CorsLayer so that a default Vary header is not set. This means that a value can now be set from a plugin. When processing the response (after all plugin processing is completed), if there is no Vary header, then insert one with a value of "origin". fixes: #1297
This comment has been minimized.
This comment has been minimized.
to make releasing easier.
o0Ignition0o
approved these changes
Aug 31, 2022
Comment on lines
+2314
to
+2344
fn it_adds_default_with_value_origin_if_no_vary_header() { | ||
let mut default_headers = HeaderMap::new(); | ||
process_vary_header(&mut default_headers); | ||
let vary_opt = default_headers.get(VARY); | ||
assert!(vary_opt.is_some()); | ||
let vary = vary_opt.expect("has a value"); | ||
assert_eq!(vary, "origin"); | ||
} | ||
|
||
#[test] | ||
fn it_leaves_vary_alone_if_set() { | ||
let mut default_headers = HeaderMap::new(); | ||
default_headers.insert(VARY, HeaderValue::from_static("*")); | ||
process_vary_header(&mut default_headers); | ||
let vary_opt = default_headers.get(VARY); | ||
assert!(vary_opt.is_some()); | ||
let vary = vary_opt.expect("has a value"); | ||
assert_eq!(vary, "*"); | ||
} | ||
|
||
#[test] | ||
fn it_leaves_varys_alone_if_there_are_more_than_one() { | ||
let mut default_headers = HeaderMap::new(); | ||
default_headers.insert(VARY, HeaderValue::from_static("one")); | ||
default_headers.append(VARY, HeaderValue::from_static("two")); | ||
process_vary_header(&mut default_headers); | ||
let vary = default_headers.get_all(VARY); | ||
assert_eq!(vary.iter().count(), 2); | ||
for value in vary { | ||
assert!(value == "one" || value == "two"); | ||
} |
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.
<3
Co-authored-by: Jeremy Lempereur <[email protected]>
Co-authored-by: Jeremy Lempereur <[email protected]>
Remove redundant cloned().
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This changes the behaviour of the CorsLayer so that a default Vary
header is only set if not specified in a user plugin.
This means that a value can now be set from a plugin. When processing
the response (after all plugin processing is completed), if there is no
Vary header, then the router will insert one with a value of "origin".
fixes: #1297