From e2d9e9e5d52045e410fb46c729f7f37ceaa0b842 Mon Sep 17 00:00:00 2001 From: Alex Snaps Date: Tue, 28 Mar 2023 13:35:33 -0400 Subject: [PATCH] Refactoring --- src/filter/http_context.rs | 11 ++++++----- src/filter/root_context.rs | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/filter/http_context.rs b/src/filter/http_context.rs index f83f48a7..02ea8895 100644 --- a/src/filter/http_context.rs +++ b/src/filter/http_context.rs @@ -18,7 +18,7 @@ const RATELIMIT_METHOD_NAME: &str = "ShouldRateLimit"; pub struct Filter { pub context_id: u32, pub config: Rc, - pub headers: Vec<(String, String)>, + pub response_headers_to_add: Vec<(String, String)>, } impl Filter { @@ -307,7 +307,7 @@ impl HttpContext for Filter { } fn on_http_response_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { - for (name, value) in &self.headers { + for (name, value) in &self.response_headers_to_add { self.add_http_response_header(name, value); } Action::Continue @@ -364,11 +364,12 @@ impl Context for Filter { } RateLimitResponse { overall_code: RateLimitResponse_Code::OK, - response_headers_to_add: response_headers, + response_headers_to_add: additional_headers, .. } => { - for header in response_headers { - self.headers.push((header.key, header.value)); + for header in additional_headers { + self.response_headers_to_add + .push((header.key, header.value)); } } } diff --git a/src/filter/root_context.rs b/src/filter/root_context.rs index 645bb287..cf66872e 100644 --- a/src/filter/root_context.rs +++ b/src/filter/root_context.rs @@ -21,7 +21,7 @@ impl RootContext for FilterRoot { Some(Box::new(Filter { context_id, config: Rc::clone(&self.config), - headers: Vec::default(), + response_headers_to_add: Vec::default(), })) }