Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 508e31c

Browse files
committedMar 14, 2024·
require async predicate to be clonable
1 parent 2d2d436 commit 508e31c

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed
 

‎tower-http/src/cors/allow_origin.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ impl AllowOrigin {
8686
/// [`CorsLayer::allow_origin`]: super::CorsLayer::allow_origin
8787
pub fn async_predicate<F, Fut>(f: F) -> Self
8888
where
89-
F: Fn(&HeaderValue, &RequestParts) -> Fut + Send + Sync + 'static,
89+
F: FnOnce(HeaderValue, &RequestParts) -> Fut + Send + Sync + 'static + Clone,
9090
Fut: Future<Output = bool> + Send + Sync + 'static,
9191
{
9292
Self(OriginInner::AsyncPredicate(Arc::new(move |v, p| {
93-
Box::pin(f(v, p))
93+
Box::pin((f.clone())(v, p))
9494
})))
9595
}
9696

@@ -130,7 +130,7 @@ impl AllowOrigin {
130130
),
131131
OriginInner::AsyncPredicate(f) => {
132132
if let Some(origin) = origin.cloned() {
133-
let fut = f(&origin, parts);
133+
let fut = f(origin.clone(), parts);
134134
AllowOriginFuture::fut(async move { fut.await.then_some((name, origin)) })
135135
} else {
136136
AllowOriginFuture::ok(None)
@@ -224,7 +224,7 @@ enum OriginInner {
224224
AsyncPredicate(
225225
Arc<
226226
dyn for<'a> Fn(
227-
&'a HeaderValue,
227+
HeaderValue,
228228
&'a RequestParts,
229229
) -> Pin<Box<dyn Future<Output = bool> + Send + 'static>>
230230
+ Send

‎tower-http/src/cors/tests.rs

-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ async fn test_allow_origin_async_predicate() {
4646
let client = Client;
4747

4848
let allow_origin = AllowOrigin::async_predicate(move |origin, parts| {
49-
let origin = origin.clone();
50-
let client = client.clone();
5149
let path = parts.uri.path().to_owned();
5250

5351
async move {

0 commit comments

Comments
 (0)
Please sign in to comment.