Skip to content

Commit

Permalink
Wire HTTP server too with new context
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Snaps <[email protected]>
  • Loading branch information
alexsnaps committed Dec 3, 2024
1 parent 36ff084 commit 103eddf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
18 changes: 9 additions & 9 deletions limitador-server/src/envoy_rls/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,18 +407,18 @@ mod tests {
namespace,

Check warning on line 407 in limitador-server/src/envoy_rls/server.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/limitador/limitador/limitador-server/src/envoy_rls/server.rs
10,
60,
vec!["x == '1'".try_into().expect("failed parsing!")],
vec!["z".try_into().expect("failed parsing!")],
vec!["descriptors[0].x == '1'".try_into().expect("failed parsing!")],
vec!["descriptors[0].z".try_into().expect("failed parsing!")],
),
Limit::new(
namespace,
0,

Check warning on line 415 in limitador-server/src/envoy_rls/server.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/limitador/limitador/limitador-server/src/envoy_rls/server.rs
60,
vec![
"x == '1'".try_into().expect("failed parsing!"),
"y == '2'".try_into().expect("failed parsing!"),
"descriptors[0].x == '1'".try_into().expect("failed parsing!"),
"descriptors[0].y == '2'".try_into().expect("failed parsing!"),
],
vec!["z".try_into().expect("failed parsing!")],
vec!["descriptors[0].z".try_into().expect("failed parsing!")],
),
]
.into_iter()
Expand Down Expand Up @@ -487,8 +487,8 @@ mod tests {
namespace,

Check warning on line 487 in limitador-server/src/envoy_rls/server.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/limitador/limitador/limitador-server/src/envoy_rls/server.rs
10,
60,
vec!["x == '1'".try_into().expect("failed parsing!")],
vec!["y".try_into().expect("failed parsing!")],
vec!["descriptors[0].x == '1'".try_into().expect("failed parsing!")],
vec!["descriptors[0].y".try_into().expect("failed parsing!")],
);

let limiter = RateLimiter::new(10_000);
Expand Down Expand Up @@ -562,8 +562,8 @@ mod tests {
namespace,

Check warning on line 562 in limitador-server/src/envoy_rls/server.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/limitador/limitador/limitador-server/src/envoy_rls/server.rs
1,
60,
vec!["x == '1'".try_into().expect("failed parsing!")],
vec!["y".try_into().expect("failed parsing!")],
vec!["descriptors[0].x == '1'".try_into().expect("failed parsing!")],
vec!["descriptors[0].y".try_into().expect("failed parsing!")],
);

let limiter = RateLimiter::new(10_000);
Expand Down
10 changes: 7 additions & 3 deletions limitador-server/src/http_api/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use paperclip::actix::{
};

Check warning on line 14 in limitador-server/src/http_api/server.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/limitador/limitador/limitador-server/src/http_api/server.rs
use std::fmt;
use std::sync::Arc;
use limitador::limit::Context;

struct RateLimitData {
limiter: Arc<Limiter>,
Expand Down Expand Up @@ -122,7 +123,8 @@ async fn check(
response_headers: _,
} = request.into_inner();
let namespace = namespace.into();
let ctx = values.into();
let mut ctx = Context::default();
ctx.list_binding("descriptors".to_string(), vec![values]);
let is_rate_limited_result = match state.get_ref().limiter() {
Limiter::Blocking(limiter) => limiter.is_rate_limited(&namespace, &ctx, delta),
Limiter::Async(limiter) => limiter.is_rate_limited(&namespace, &ctx, delta).await,
Expand Down Expand Up @@ -153,7 +155,8 @@ async fn report(
response_headers: _,
} = request.into_inner();
let namespace = namespace.into();
let ctx = values.into();
let mut ctx = Context::default();
ctx.list_binding("descriptors".to_string(), vec![values]);
let update_counters_result = match data.get_ref().limiter() {
Limiter::Blocking(limiter) => limiter.update_counters(&namespace, &ctx, delta),
Limiter::Async(limiter) => limiter.update_counters(&namespace, &ctx, delta).await,
Expand All @@ -178,7 +181,8 @@ async fn check_and_report(
response_headers,
} = request.into_inner();
let namespace = namespace.into();
let ctx = values.into();
let mut ctx = Context::default();
ctx.list_binding("descriptors".to_string(), vec![values]);
let rate_limit_data = data.get_ref();
let rate_limited_and_update_result = match rate_limit_data.limiter() {
Limiter::Blocking(limiter) => limiter.check_rate_limited_and_update(
Expand Down

0 comments on commit 103eddf

Please sign in to comment.