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

add support for setting vary header in plugins #1660

Merged
merged 6 commits into from
Aug 31, 2022
Merged

Conversation

garypen
Copy link
Contributor

@garypen garypen commented Aug 31, 2022

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

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
@garypen garypen self-assigned this Aug 31, 2022
@github-actions

This comment has been minimized.

NEXT_CHANGELOG.md Outdated Show resolved Hide resolved
apollo-router/src/axum_http_server_factory.rs Outdated Show resolved Hide resolved
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");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

<3

docs/source/configuration/cors.mdx Outdated Show resolved Hide resolved
@garypen garypen merged commit 0901b4e into main Aug 31, 2022
@garypen garypen deleted the garypen/1297-vary-fix branch August 31, 2022 14:28
@abernix abernix mentioned this pull request Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to Set Vary Header in Plugins (rust or rhai)
2 participants