Skip to content

Commit

Permalink
minor renames
Browse files Browse the repository at this point in the history
  • Loading branch information
blind-oracle committed Jun 3, 2024
1 parent d72da6a commit 11569cc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
26 changes: 15 additions & 11 deletions src/routing/middleware/rate_limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ impl KeyExtractor for IpKeyExtractor {
}
}

pub fn build_middleware<T: KeyExtractor + Send + Sync + 'static>(
pub fn layer_by_ip(
rps: u32,
burst_size: u32,
) -> Result<GovernorLayer<IpKeyExtractor, NoOpMiddleware<QuantaInstant>>, Error> {
layer(rps, burst_size, IpKeyExtractor, RateLimitCause::Normal)
}

pub fn layer<T: KeyExtractor>(
rps: u32,
burst_size: u32,
key_extractor: T,
Expand Down Expand Up @@ -82,7 +89,7 @@ mod tests {
http::{ConnInfo, Stats},
routing::{
error_cause::{ErrorCause, RateLimitCause},
middleware::rate_limiter::{build_middleware, IpKeyExtractor},
middleware::rate_limiter::{layer, IpKeyExtractor},
},
};

Expand Down Expand Up @@ -111,9 +118,8 @@ mod tests {
let rps = 1;
let burst_size = 5;

let rate_limiter_mw =
build_middleware(rps, burst_size, IpKeyExtractor, RateLimitCause::Normal)
.expect("failed to build middleware");
let rate_limiter_mw = layer(rps, burst_size, IpKeyExtractor, RateLimitCause::Normal)
.expect("failed to build middleware");

let mut app = Router::new()
.route("/", post(handler))
Expand Down Expand Up @@ -143,9 +149,8 @@ mod tests {
let rps = 10;
let burst_size = 1;

let rate_limiter_mw =
build_middleware(rps, burst_size, IpKeyExtractor, RateLimitCause::Normal)
.expect("failed to build middleware");
let rate_limiter_mw = layer(rps, burst_size, IpKeyExtractor, RateLimitCause::Normal)
.expect("failed to build middleware");

let mut app = Router::new()
.route("/", post(handler))
Expand Down Expand Up @@ -179,9 +184,8 @@ mod tests {
let rps = 1;
let burst_size = 1;

let rate_limiter_mw =
build_middleware(rps, burst_size, IpKeyExtractor, RateLimitCause::Normal)
.expect("failed to build middleware");
let rate_limiter_mw = layer(rps, burst_size, IpKeyExtractor, RateLimitCause::Normal)
.expect("failed to build middleware");

let mut app = Router::new()
.route("/", post(handler))
Expand Down
10 changes: 1 addition & 9 deletions src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,7 @@ pub fn setup_router(
cli.cert.issuer_urls.clone(),
));
let router_issuer = Router::new()
.layer(
rate_limiter::build_middleware(
5,
10,
rate_limiter::IpKeyExtractor,
RateLimitCause::Normal,
)
.unwrap(),
)
.layer(rate_limiter::layer_by_ip(5, 10).unwrap())
.route(
"/:id",
get(proxy::issuer_proxy)
Expand Down

0 comments on commit 11569cc

Please sign in to comment.