Skip to content

Commit 51be8df

Browse files
committed
chore: format
1 parent ac41da7 commit 51be8df

10 files changed

Lines changed: 50 additions & 51 deletions

File tree

tako-plugins/src/middleware/circuit_breaker.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
use std::future::Future;
2020
use std::pin::Pin;
2121
use std::sync::Arc;
22-
use std::sync::atomic::AtomicU64;
2322
use std::sync::atomic::AtomicU8;
23+
use std::sync::atomic::AtomicU64;
2424
use std::sync::atomic::Ordering;
2525
use std::time::Duration;
2626
use std::time::Instant;
@@ -202,7 +202,12 @@ impl IntoMiddleware for CircuitBreaker {
202202
// Cool-down elapsed: transition to half-open if we win the race.
203203
if state
204204
.state
205-
.compare_exchange(STATE_OPEN, STATE_HALF_OPEN, Ordering::AcqRel, Ordering::Acquire)
205+
.compare_exchange(
206+
STATE_OPEN,
207+
STATE_HALF_OPEN,
208+
Ordering::AcqRel,
209+
Ordering::Acquire,
210+
)
206211
.is_ok()
207212
{
208213
state.reset_window();

tako-plugins/src/middleware/csrf.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,17 @@ fn extract_cookie<'a>(req: &'a Request, name: &str) -> Option<&'a str> {
149149

150150
fn origin_allowed(value: &str, allow: &[String]) -> bool {
151151
// Match by exact scheme://host[:port] prefix, ignoring path.
152-
let target = value
153-
.splitn(4, '/')
154-
.take(3)
155-
.collect::<Vec<_>>()
156-
.join("/");
152+
let target = value.splitn(4, '/').take(3).collect::<Vec<_>>().join("/");
157153
allow.iter().any(|o| o == &target)
158154
}
159155

160156
fn build_cookie(name: &str, token: &str, secure: bool, same_site: SameSite) -> String {
161-
let mut s = format!("{}={}; Path=/; SameSite={}", name, token, same_site_str(same_site));
157+
let mut s = format!(
158+
"{}={}; Path=/; SameSite={}",
159+
name,
160+
token,
161+
same_site_str(same_site)
162+
);
162163
if secure || matches!(same_site, SameSite::None) {
163164
s.push_str("; Secure");
164165
}
@@ -335,9 +336,7 @@ fn ensure_csrf_cookie(
335336
if already_set {
336337
return;
337338
}
338-
let token = preferred_token
339-
.clone()
340-
.unwrap_or_else(generate_csrf_token);
339+
let token = preferred_token.clone().unwrap_or_else(generate_csrf_token);
341340
if bind_to_session {
342341
if let Some(session) = resp.extensions_mut().get::<Session>().cloned() {
343342
session.set(session_key, token.clone());

tako-plugins/src/middleware/hmac_signature.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ use tako_core::types::Response;
3030
type HmacSha256 = Hmac<Sha256>;
3131

3232
/// Canonicalization strategy: produces the byte string that gets HMAC'd.
33-
type CanonicalFn =
34-
Arc<dyn Fn(&http::request::Parts, &[u8]) -> Vec<u8> + Send + Sync + 'static>;
33+
type CanonicalFn = Arc<dyn Fn(&http::request::Parts, &[u8]) -> Vec<u8> + Send + Sync + 'static>;
3534

3635
/// Signature verification middleware.
3736
pub struct HmacSignature {

tako-plugins/src/middleware/json_schema.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ fn problem(status: StatusCode, errors: &[String]) -> Response {
9090
});
9191
let mut resp = http::Response::builder()
9292
.status(status)
93-
.body(TakoBody::from(serde_json::to_vec(&body).unwrap_or_default()))
93+
.body(TakoBody::from(
94+
serde_json::to_vec(&body).unwrap_or_default(),
95+
))
9496
.expect("valid problem response");
9597
resp.headers_mut().insert(
9698
CONTENT_TYPE,
@@ -132,7 +134,10 @@ impl IntoMiddleware for JsonSchema {
132134
}
133135
match serde_json::from_slice::<Value>(&collected) {
134136
Ok(value) => {
135-
let errors: Vec<String> = validator.iter_errors(&value).map(|e| e.to_string()).collect();
137+
let errors: Vec<String> = validator
138+
.iter_errors(&value)
139+
.map(|e| e.to_string())
140+
.collect();
136141
if !errors.is_empty() {
137142
return problem(StatusCode::BAD_REQUEST, &errors);
138143
}
@@ -157,7 +162,10 @@ impl IntoMiddleware for JsonSchema {
157162
}
158163
match serde_json::from_slice::<Value>(&collected) {
159164
Ok(value) => {
160-
let errors: Vec<String> = validator.iter_errors(&value).map(|e| e.to_string()).collect();
165+
let errors: Vec<String> = validator
166+
.iter_errors(&value)
167+
.map(|e| e.to_string())
168+
.collect();
161169
if !errors.is_empty() {
162170
return problem(StatusCode::INTERNAL_SERVER_ERROR, &errors);
163171
}

tako-plugins/src/middleware/jwt_auth.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ impl RevocationList for InMemoryRevocationList {
8888

8989
/// Optional remote introspection. Returns true when the token is still
9090
/// valid; false when it has been revoked / expired upstream.
91-
pub type IntrospectionFn = Arc<
92-
dyn Fn(&str) -> Pin<Box<dyn Future<Output = bool> + Send + 'static>> + Send + Sync + 'static,
93-
>;
91+
pub type IntrospectionFn =
92+
Arc<dyn Fn(&str) -> Pin<Box<dyn Future<Output = bool> + Send + 'static>> + Send + Sync + 'static>;
9493

9594
/// Closure that extracts a `jti` (or any revocation-list key) from the
9695
/// verifier's decoded claims. Required when wiring up [`JwtAuth::revocation`].
@@ -218,7 +217,6 @@ impl<V: JwtVerifier> IntoMiddleware for JwtAuth<V> {
218217
}
219218
}
220219

221-
222220
#[cfg(feature = "jwt-simple")]
223221
mod jwt_simple_impl {
224222
use std::collections::HashMap;
@@ -411,7 +409,9 @@ mod jwt_simple_impl {
411409
opts.allowed_audiences = Some(set);
412410
}
413411

414-
key.verify_token::<C>(token, opts).map_err(|e| e.to_string())
412+
key
413+
.verify_token::<C>(token, opts)
414+
.map_err(|e| e.to_string())
415415
}
416416
}
417417
}

tako-plugins/src/middleware/security_headers.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,7 @@ impl IntoMiddleware for SecurityHeaders {
239239
let nonce = rand_nonce();
240240
let value = template.replace("{nonce}", &nonce);
241241
req.extensions_mut().insert(CspNonce(nonce));
242-
HeaderValue::from_str(&value)
243-
.ok()
244-
.map(|hv| (hv, *header))
242+
HeaderValue::from_str(&value).ok().map(|hv| (hv, *header))
245243
}
246244
};
247245

tako-plugins/src/middleware/session.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ impl SessionStoreHandle {
146146
where
147147
F: FnMut(&str, &serde_json::Map<String, serde_json::Value>) -> bool,
148148
{
149-
self
150-
.store
151-
.revoke_predicate(|k, v| !pred(k, &v.data));
149+
self.store.revoke_predicate(|k, v| !pred(k, &v.data));
152150
}
153151
}
154152

@@ -430,20 +428,10 @@ impl IntoMiddleware for SessionMiddleware {
430428
if let Some(id) = inbound_id.as_ref() {
431429
store.remove(id);
432430
}
433-
(
434-
generate_session_id(),
435-
serde_json::Map::new(),
436-
now,
437-
false,
438-
)
431+
(generate_session_id(), serde_json::Map::new(), now, false)
439432
}
440433
},
441-
None => (
442-
generate_session_id(),
443-
serde_json::Map::new(),
444-
now,
445-
false,
446-
),
434+
None => (generate_session_id(), serde_json::Map::new(), now, false),
447435
};
448436

449437
let session = Session::new(data);

tako-plugins/src/plugins/cors.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@ impl CorsBuilder {
303303
#[inline]
304304
#[must_use]
305305
pub fn allow_origin_suffix(mut self, suffix: impl Into<String>) -> Self {
306-
self.0.origin_matchers.push(OriginMatcher::Suffix(suffix.into()));
306+
self
307+
.0
308+
.origin_matchers
309+
.push(OriginMatcher::Suffix(suffix.into()));
307310
self
308311
}
309312

@@ -314,7 +317,10 @@ impl CorsBuilder {
314317
where
315318
F: Fn(&str) -> bool + Send + Sync + 'static,
316319
{
317-
self.0.origin_matchers.push(OriginMatcher::Custom(Arc::new(f)));
320+
self
321+
.0
322+
.origin_matchers
323+
.push(OriginMatcher::Custom(Arc::new(f)));
318324
self
319325
}
320326

tako-plugins/src/plugins/metrics.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,8 @@ impl PrometheusMetricsConfig {
480480
/// Installs a Prometheus metrics backend and a scrape endpoint on the router.
481481
pub fn install(self, router: &mut Router) -> Arc<Registry> {
482482
let registry = Arc::new(Registry::new());
483-
let backend = prometheus_backend::PrometheusMetricsBackend::with_buckets(
484-
(*registry).clone(),
485-
self.buckets,
486-
);
483+
let backend =
484+
prometheus_backend::PrometheusMetricsBackend::with_buckets((*registry).clone(), self.buckets);
487485
let plugin = MetricsPlugin::new(Arc::new(backend));
488486

489487
router.plugin(plugin);

tako-rs/tests/middleware.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ async fn middleware_chain_order() {
643643
#[tokio::test]
644644
async fn timeout_returns_503_when_exceeded() {
645645
use std::time::Duration;
646+
646647
use tako::middleware::timeout::Timeout;
647648

648649
let mut router = Router::new();
@@ -659,6 +660,7 @@ async fn timeout_returns_503_when_exceeded() {
659660
#[tokio::test]
660661
async fn timeout_passes_when_within_deadline() {
661662
use std::time::Duration;
663+
662664
use tako::middleware::timeout::Timeout;
663665

664666
let mut router = Router::new();
@@ -713,10 +715,7 @@ async fn traceparent_propagates_inbound() {
713715
let resp = router.dispatch(req).await;
714716
let response_header = resp.headers().get(TRACEPARENT).unwrap().to_str().unwrap();
715717
assert!(response_header.contains("0123456789abcdef0123456789abcdef"));
716-
assert_eq!(
717-
body_str(resp).await,
718-
"0123456789abcdef0123456789abcdef"
719-
);
718+
assert_eq!(body_str(resp).await, "0123456789abcdef0123456789abcdef");
720719
}
721720

722721
#[tokio::test]
@@ -782,8 +781,7 @@ async fn tenant_extracted_from_header() {
782781
.unwrap_or_else(|| "no-tenant".into())
783782
});
784783
router.middleware(
785-
TenantMiddleware::from_header(http::HeaderName::from_static("x-tenant-id"))
786-
.into_middleware(),
784+
TenantMiddleware::from_header(http::HeaderName::from_static("x-tenant-id")).into_middleware(),
787785
);
788786

789787
let mut req = make_req(Method::GET, "/");

0 commit comments

Comments
 (0)