diff --git a/src/auth_action.rs b/src/auth_action.rs index 40c7d9e..5b1dbd9 100644 --- a/src/auth_action.rs +++ b/src/auth_action.rs @@ -1,7 +1,7 @@ use crate::configuration::{Action, FailureMode, Service}; use crate::data::{store_metadata, Predicate, PredicateVec}; use crate::envoy::{CheckResponse, CheckResponse_oneof_http_response, HeaderValueOption}; -use crate::service::{GrpcErrResponse, GrpcService}; +use crate::service::{GrpcErrResponse, GrpcService, Headers}; use log::debug; use std::rc::Rc; @@ -45,7 +45,7 @@ impl AuthAction { pub fn process_response( &self, check_response: CheckResponse, - ) -> Result, GrpcErrResponse> { + ) -> Result { //todo(adam-cattermole):hostvar resolver? // store dynamic metadata in filter state debug!("process_response(auth): store_metadata"); @@ -92,7 +92,7 @@ impl AuthAction { } } - fn get_header_vec(headers: &[HeaderValueOption]) -> Vec<(String, String)> { + fn get_header_vec(headers: &[HeaderValueOption]) -> Headers { headers .iter() .map(|header| { diff --git a/src/filter/operations.rs b/src/filter/operations.rs index 16206c5..0e62a29 100644 --- a/src/filter/operations.rs +++ b/src/filter/operations.rs @@ -1,6 +1,6 @@ use crate::filter::operations::Operation::SendGrpcRequest; use crate::runtime_action_set::RuntimeActionSet; -use crate::service::{GrpcErrResponse, GrpcRequest, IndexedGrpcRequest}; +use crate::service::{GrpcErrResponse, GrpcRequest, Headers, IndexedGrpcRequest}; use std::rc::Rc; pub enum Operation { @@ -86,15 +86,15 @@ impl GrpcMessageReceiverOperation { } pub struct HeadersOperation { - headers: Vec<(String, String)>, + headers: Headers, } impl HeadersOperation { - pub fn new(headers: Vec<(String, String)>) -> Self { + pub fn new(headers: Headers) -> Self { Self { headers } } - pub fn headers(self) -> Vec<(String, String)> { + pub fn headers(self) -> Headers { self.headers } } diff --git a/src/ratelimit_action.rs b/src/ratelimit_action.rs index 6d6fa0e..c8d6cf0 100644 --- a/src/ratelimit_action.rs +++ b/src/ratelimit_action.rs @@ -5,7 +5,7 @@ use crate::envoy::{ HeaderValue, RateLimitDescriptor, RateLimitDescriptor_Entry, RateLimitResponse, RateLimitResponse_Code, StatusCode, }; -use crate::service::{GrpcErrResponse, GrpcService}; +use crate::service::{GrpcErrResponse, GrpcService, Headers}; use cel_interpreter::Value; use log::{debug, error}; use protobuf::RepeatedField; @@ -206,7 +206,7 @@ impl RateLimitAction { } } - fn get_header_vec(headers: RepeatedField) -> Vec<(String, String)> { + fn get_header_vec(headers: RepeatedField) -> Headers { headers .iter() .map(|header| (header.key.to_owned(), header.value.to_owned())) diff --git a/src/runtime_action.rs b/src/runtime_action.rs index c9a4b9f..e2cbbc9 100644 --- a/src/runtime_action.rs +++ b/src/runtime_action.rs @@ -3,7 +3,7 @@ use crate::configuration::{Action, FailureMode, Service, ServiceType}; use crate::ratelimit_action::RateLimitAction; use crate::service::auth::AuthService; use crate::service::rate_limit::RateLimitService; -use crate::service::{GrpcErrResponse, GrpcService}; +use crate::service::{GrpcErrResponse, GrpcService, Headers}; use log::debug; use protobuf::Message; use std::collections::HashMap; @@ -67,7 +67,7 @@ impl RuntimeAction { } } - pub fn process_response(&self, msg: &[u8]) -> Result, GrpcErrResponse> { + pub fn process_response(&self, msg: &[u8]) -> Result { match self { Self::Auth(auth_action) => match Message::parse_from_bytes(msg) { Ok(check_response) => auth_action.process_response(check_response), diff --git a/src/runtime_action_set.rs b/src/runtime_action_set.rs index e2a5837..584e3f1 100644 --- a/src/runtime_action_set.rs +++ b/src/runtime_action_set.rs @@ -1,7 +1,7 @@ use crate::configuration::{ActionSet, Service}; use crate::data::{Predicate, PredicateVec}; use crate::runtime_action::RuntimeAction; -use crate::service::{GrpcErrResponse, IndexedGrpcRequest}; +use crate::service::{GrpcErrResponse, Headers, IndexedGrpcRequest}; use std::collections::HashMap; use std::rc::Rc; @@ -80,7 +80,7 @@ impl RuntimeActionSet { &self, index: usize, msg: &[u8], - ) -> Result<(Option, Vec<(String, String)>), GrpcErrResponse> { + ) -> Result<(Option, Headers), GrpcErrResponse> { self.runtime_actions[index] .process_response(msg) .map(|headers| { diff --git a/src/service.rs b/src/service.rs index 7e0f036..cd88921 100644 --- a/src/service.rs +++ b/src/service.rs @@ -128,15 +128,16 @@ impl GrpcRequest { } } +pub type Headers = Vec<(String, String)>; #[derive(Debug)] pub struct GrpcErrResponse { status_code: u32, - response_headers: Vec<(String, String)>, + response_headers: Headers, body: String, } impl GrpcErrResponse { - pub fn new(status_code: u32, response_headers: Vec<(String, String)>, body: String) -> Self { + pub fn new(status_code: u32, response_headers: Headers, body: String) -> Self { Self { status_code, response_headers,