Skip to content

Commit

Permalink
Simplify AllowOrigin::list
Browse files Browse the repository at this point in the history
  • Loading branch information
jplatte committed Jan 27, 2024
1 parent 6f992ce commit 2d059c6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tower-http/src/cors/allow_origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ impl AllowOrigin {
I: IntoIterator<Item = HeaderValue>,
{
let origins = origins.into_iter().collect::<Vec<_>>();
if origins.iter().any(|o| o == WILDCARD) {
panic!("Wildcard origin (`*`) cannot be passed to `AllowOrigin::list`. Use `AllowOrigin::any()` instead");
} else {
Self(OriginInner::List(origins))
if origins.contains(&WILDCARD) {
panic!(
"Wildcard origin (`*`) cannot be passed to `AllowOrigin::list`. \
Use `AllowOrigin::any()` instead"
);
}

Self(OriginInner::List(origins))
}

/// Set the allowed origins from a predicate
Expand Down

0 comments on commit 2d059c6

Please sign in to comment.