diff --git a/command/src/command.proto b/command/src/command.proto index 0eeb548a5..b604ffcb8 100644 --- a/command/src/command.proto +++ b/command/src/command.proto @@ -244,13 +244,14 @@ message RequestHttpFrontend { repeated Header headers = 15; } -enum Position { - FRONTEND = 1; - BACKEND = 2; +enum HeaderPosition { + REQUEST = 1; + RESPONSE = 2; + BOTH = 3; } message Header { - required Position position = 1; + required HeaderPosition position = 1; required string key = 2; required string val = 3; } diff --git a/command/src/config.rs b/command/src/config.rs index 0f17a9b02..3c3649095 100644 --- a/command/src/config.rs +++ b/command/src/config.rs @@ -62,7 +62,7 @@ use crate::{ logging::AccessLogFormat, proto::command::{ request::RequestType, ActivateListener, AddBackend, AddCertificate, CertificateAndKey, - Cluster, Header, HttpListenerConfig, HttpsListenerConfig, ListenerType, + Cluster, Header, HeaderPosition, HttpListenerConfig, HttpsListenerConfig, ListenerType, LoadBalancingAlgorithms, LoadBalancingParams, LoadMetric, MetricsConfiguration, PathRule, ProtobufAccessLogFormat, ProxyProtocolConfig, RedirectPolicy, RedirectScheme, Request, RequestHttpFrontend, RequestTcpFrontend, RulePosition, ServerConfig, ServerMetricsConfig, @@ -609,6 +609,14 @@ pub enum PathRuleType { Equals, } +#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +pub struct HeaderConfig { + position: HeaderPosition, + key: String, + val: String, +} + #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(deny_unknown_fields)] pub struct FileClusterFrontendConfig { @@ -635,7 +643,7 @@ pub struct FileClusterFrontendConfig { pub rewrite_path: Option, pub rewrite_port: Option, #[serde(default)] - pub headers: Vec
, + pub headers: Vec, } impl FileClusterFrontendConfig { @@ -897,7 +905,7 @@ pub struct HttpFrontendConfig { pub rewrite_host: Option, pub rewrite_path: Option, pub rewrite_port: Option, - pub headers: Vec
, + pub headers: Vec, } fn default_rule_position() -> RulePosition { @@ -909,6 +917,16 @@ impl HttpFrontendConfig { let mut v = Vec::new(); let tags = self.tags.clone().unwrap_or_default(); + let headers = self + .headers + .iter() + .cloned() + .map(|h| Header { + position: h.position.into(), + key: h.key, + val: h.val, + }) + .collect(); if self.key.is_some() && self.certificate.is_some() { v.push( @@ -946,7 +964,7 @@ impl HttpFrontendConfig { rewrite_host: self.rewrite_host.clone(), rewrite_path: self.rewrite_path.clone(), rewrite_port: self.rewrite_port.map(|x| x as u32), - headers: self.headers.clone(), + headers, }) .into(), ); @@ -968,7 +986,7 @@ impl HttpFrontendConfig { rewrite_host: self.rewrite_host.clone(), rewrite_path: self.rewrite_path.clone(), rewrite_port: self.rewrite_port.map(|x| x as u32), - headers: self.headers.clone(), + headers, }) .into(), ); diff --git a/lib/src/protocol/kawa_h1/answers.rs b/lib/src/protocol/kawa_h1/answers.rs index 9d844f82c..b0ea8b49c 100644 --- a/lib/src/protocol/kawa_h1/answers.rs +++ b/lib/src/protocol/kawa_h1/answers.rs @@ -543,9 +543,9 @@ Sozu-Id: %REQUEST_ID\r \"cluster_id\": \"%CLUSTER_ID\", \"backend_id\": \"%BACKEND_ID\", \"parsing_phase\": \"%PHASE\", - \"successfully_parsed\": \"%SUCCESSFULLY_PARSED\", - \"partially_parsed\": \"%PARTIALLY_PARSED\", - \"invalid\": \"%INVALID\" + \"successfully_parsed\": %SUCCESSFULLY_PARSED, + \"partially_parsed\": %PARTIALLY_PARSED, + \"invalid\": %INVALID }

Response could not be parsed. %MESSAGE

diff --git a/lib/src/router/mod.rs b/lib/src/router/mod.rs index 0e8ce2a29..ea95e6115 100644 --- a/lib/src/router/mod.rs +++ b/lib/src/router/mod.rs @@ -14,7 +14,7 @@ use regex::bytes::Regex; use sozu_command::{ logging::CachedTags, proto::command::{ - PathRule as CommandPathRule, PathRuleKind, Position, RedirectPolicy, RedirectScheme, + HeaderPosition, PathRule as CommandPathRule, PathRuleKind, RedirectPolicy, RedirectScheme, RulePosition, }, response::HttpFrontend, @@ -852,16 +852,17 @@ impl Frontend { let mut headers_request = Vec::new(); let mut headers_response = Vec::new(); for header in headers { - if header.position() == Position::Frontend { - headers_request.push(HeaderEdit { - key: header.key.clone().into_bytes().into(), - val: header.val.clone().into_bytes().into(), - }); - } else { - headers_response.push(HeaderEdit { - key: header.key.clone().into_bytes().into(), - val: header.val.clone().into_bytes().into(), - }); + let edit = HeaderEdit { + key: header.key.clone().into_bytes().into(), + val: header.val.clone().into_bytes().into(), + }; + match header.position() { + HeaderPosition::Request => headers_request.push(edit), + HeaderPosition::Response => headers_response.push(edit), + HeaderPosition::Both => { + headers_request.push(edit.clone()); + headers_response.push(edit); + } } } Ok(Frontend {