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

enable cors/tests.rs and make it pass #473

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tower-http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Fixed

- **compression:** Skip compression for range requests ([#446])
- **cors:** *Actually* keep Vary headers set by the inner service when setting response headers ([#473])
- Version 0.5.1 intended to ship this, but the implementation was buggy and didn't actually do anything

[#399]: https://github.com/tower-rs/tower-http/pull/399
[#446]: https://github.com/tower-rs/tower-http/pull/446
[#473]: https://github.com/tower-rs/tower-http/pull/473

# 0.5.1 (January 14, 2024)

Expand Down
9 changes: 7 additions & 2 deletions tower-http/src/cors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ mod expose_headers;
mod max_age;
mod vary;

#[cfg(test)]
mod tests;

pub use self::{
allow_credentials::AllowCredentials, allow_headers::AllowHeaders, allow_methods::AllowMethods,
allow_origin::AllowOrigin, allow_private_network::AllowPrivateNetwork,
Expand Down Expand Up @@ -682,13 +685,15 @@ where
KindProj::CorsCall { future, headers } => {
let mut response: Response<B> = ready!(future.poll(cx))?;

let response_headers = response.headers_mut();

// vary header can have multiple values, don't overwrite
// previously-set value(s).
if let Some(vary) = headers.remove(header::VARY) {
headers.append(header::VARY, vary);
response_headers.append(header::VARY, vary);
}
// extend will overwrite previous headers of remaining names
response.headers_mut().extend(headers.drain());
response_headers.extend(headers.drain());

Poll::Ready(Ok(response))
}
Expand Down
2 changes: 1 addition & 1 deletion tower-http/src/cors/tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::convert::Infallible;

use crate::test_helpers::Body;
use http::{header, HeaderValue, Request, Response};
use hyper::Body;
use tower::{service_fn, util::ServiceExt, Layer};

use crate::cors::CorsLayer;
Expand Down
Loading