Skip to content

Commit

Permalink
don't push
Browse files Browse the repository at this point in the history
Signed-off-by: Eloi DEMOLIS <[email protected]>
  • Loading branch information
Wonshtrum committed May 6, 2024
1 parent 96b2b9f commit 00d6f96
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 175 deletions.
2 changes: 0 additions & 2 deletions bin/src/ctl/request_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ impl CommandManager {
Some(tags) => tags,
None => BTreeMap::new(),
},
h2: h2.unwrap_or(false),
})
.into(),
),
Expand Down Expand Up @@ -301,7 +300,6 @@ impl CommandManager {
Some(tags) => tags,
None => BTreeMap::new(),
},
h2: h2.unwrap_or(false),
})
.into(),
),
Expand Down
2 changes: 1 addition & 1 deletion command/src/command.proto
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ message RequestHttpFrontend {
required RulePosition position = 6 [default = TREE];
// custom tags to identify the frontend in the access logs
map<string, string> tags = 7;
required bool h2 = 8;
}

message RequestTcpFrontend {
Expand Down Expand Up @@ -383,6 +382,7 @@ message Cluster {
required LoadBalancingAlgorithms load_balancing = 5 [default = ROUND_ROBIN];
optional string answer_503 = 6;
optional LoadMetric load_metric = 7;
required bool http2 = 8;
}

enum LoadBalancingAlgorithms {
Expand Down
12 changes: 6 additions & 6 deletions command/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,6 @@ pub struct FileClusterFrontendConfig {
#[serde(default = "default_rule_position")]
pub position: RulePosition,
pub tags: Option<BTreeMap<String, String>>,
pub h2: Option<bool>,
}

impl FileClusterFrontendConfig {
Expand Down Expand Up @@ -767,7 +766,6 @@ impl FileClusterFrontendConfig {
path,
method: self.method.clone(),
tags: self.tags.clone(),
h2: self.h2.unwrap_or(false),
})
}
}
Expand All @@ -784,6 +782,7 @@ pub enum ListenerProtocol {
#[serde(deny_unknown_fields, rename_all = "lowercase")]
pub enum FileClusterProtocolConfig {
Http,
Http2,
Tcp,
}

Expand Down Expand Up @@ -873,7 +872,7 @@ impl FileClusterConfig {
load_metric: self.load_metric,
}))
}
FileClusterProtocolConfig::Http => {
FileClusterProtocolConfig::Http | FileClusterProtocolConfig::Http2 => {
let mut frontends = Vec::new();
for frontend in self.frontends {
let http_frontend = frontend.to_http_front(cluster_id)?;
Expand All @@ -891,6 +890,7 @@ impl FileClusterConfig {

Ok(ClusterConfig::Http(HttpClusterConfig {
cluster_id: cluster_id.to_string(),
http2: self.protocol == FileClusterProtocolConfig::Http2,
frontends,
backends: self.backends,
sticky_session: self.sticky_session.unwrap_or(false),
Expand Down Expand Up @@ -919,7 +919,6 @@ pub struct HttpFrontendConfig {
#[serde(default)]
pub position: RulePosition,
pub tags: Option<BTreeMap<String, String>>,
pub h2: bool,
}

impl HttpFrontendConfig {
Expand Down Expand Up @@ -955,7 +954,6 @@ impl HttpFrontendConfig {
path: self.path.clone(),
method: self.method.clone(),
position: self.position.into(),
h2: self.h2,
tags,
})
.into(),
Expand All @@ -970,7 +968,6 @@ impl HttpFrontendConfig {
path: self.path.clone(),
method: self.method.clone(),
position: self.position.into(),
h2: self.h2,
tags,
})
.into(),
Expand All @@ -985,6 +982,7 @@ impl HttpFrontendConfig {
#[serde(deny_unknown_fields)]
pub struct HttpClusterConfig {
pub cluster_id: String,
pub http2: bool,
pub frontends: Vec<HttpFrontendConfig>,
pub backends: Vec<BackendConfig>,
pub sticky_session: bool,
Expand All @@ -1000,6 +998,7 @@ impl HttpClusterConfig {
cluster_id: self.cluster_id.clone(),
sticky_session: self.sticky_session,
https_redirect: self.https_redirect,
http2: self.http2,
proxy_protocol: None,
load_balancing: self.load_balancing as i32,
answer_503: self.answer_503.clone(),
Expand Down Expand Up @@ -1059,6 +1058,7 @@ impl TcpClusterConfig {
cluster_id: self.cluster_id.clone(),
sticky_session: false,
https_redirect: false,
http2: false,
proxy_protocol: self.proxy_protocol.map(|s| s as i32),
load_balancing: self.load_balancing as i32,
load_metric: self.load_metric.map(|s| s as i32),
Expand Down
1 change: 0 additions & 1 deletion command/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ impl RequestHttpFrontend {
}
})?,
tags: Some(self.tags),
h2: self.h2,
})
}
}
Expand Down
2 changes: 0 additions & 2 deletions command/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ pub struct HttpFrontend {
#[serde(default)]
pub position: RulePosition,
pub tags: Option<BTreeMap<String, String>>,
pub h2: bool,
}

impl From<HttpFrontend> for RequestHttpFrontend {
Expand All @@ -55,7 +54,6 @@ impl From<HttpFrontend> for RequestHttpFrontend {
path: val.path,
method: val.method,
position: val.position.into(),
h2: val.h2,
tags,
}
}
Expand Down
26 changes: 5 additions & 21 deletions lib/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ impl L7ListenerHandler for HttpListener {

let now = Instant::now();

if let Route::Cluster { id: cluster, .. } = &route {
if let Route::Cluster(cluster) = &route {
time!("frontend_matching_time", cluster, (now - start).as_millis());
}

Expand Down Expand Up @@ -1374,7 +1374,6 @@ mod tests {
position: RulePosition::Tree,
cluster_id: Some(cluster_id1),
tags: None,
h2: false,
})
.expect("Could not add http frontend");
fronts
Expand All @@ -1386,7 +1385,6 @@ mod tests {
position: RulePosition::Tree,
cluster_id: Some(cluster_id2),
tags: None,
h2: false,
})
.expect("Could not add http frontend");
fronts
Expand All @@ -1398,7 +1396,6 @@ mod tests {
position: RulePosition::Tree,
cluster_id: Some(cluster_id3),
tags: None,
h2: false,
})
.expect("Could not add http frontend");
fronts
Expand All @@ -1410,7 +1407,6 @@ mod tests {
position: RulePosition::Tree,
cluster_id: Some("cluster_1".to_owned()),
tags: None,
h2: false,
})
.expect("Could not add http frontend");

Expand Down Expand Up @@ -1440,31 +1436,19 @@ mod tests {
let frontend5 = listener.frontend_from_request("domain", "/", &Method::Get);
assert_eq!(
frontend1.expect("should find frontend"),
Route::Cluster {
id: "cluster_1".to_string(),
h2: false
}
Route::Cluster("cluster_1".to_string())
);
assert_eq!(
frontend2.expect("should find frontend"),
Route::Cluster {
id: "cluster_1".to_string(),
h2: false
}
Route::Cluster("cluster_1".to_string())
);
assert_eq!(
frontend3.expect("should find frontend"),
Route::Cluster {
id: "cluster_2".to_string(),
h2: false
}
Route::Cluster("cluster_2".to_string())
);
assert_eq!(
frontend4.expect("should find frontend"),
Route::Cluster {
id: "cluster_3".to_string(),
h2: false
}
Route::Cluster("cluster_3".to_string())
);
assert!(frontend5.is_err());
}
Expand Down
42 changes: 9 additions & 33 deletions lib/src/https.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ impl L7ListenerHandler for HttpsListener {

let now = Instant::now();

if let Route::Cluster { id: cluster, .. } = &route {
if let Route::Cluster(cluster) = &route {
time!("frontend_matching_time", cluster, (now - start).as_millis());
}

Expand Down Expand Up @@ -1557,37 +1557,25 @@ mod tests {
"lolcatho.st".as_bytes(),
&PathRule::Prefix(uri1),
&MethodRule::new(None),
&Route::Cluster {
id: cluster_id1.clone(),
h2: false
}
&Route::Cluster(cluster_id1.clone())
));
assert!(fronts.add_tree_rule(
"lolcatho.st".as_bytes(),
&PathRule::Prefix(uri2),
&MethodRule::new(None),
&Route::Cluster {
id: cluster_id2,
h2: false
}
&Route::Cluster(cluster_id2)
));
assert!(fronts.add_tree_rule(
"lolcatho.st".as_bytes(),
&PathRule::Prefix(uri3),
&MethodRule::new(None),
&Route::Cluster {
id: cluster_id3,
h2: false
}
&Route::Cluster(cluster_id3)
));
assert!(fronts.add_tree_rule(
"other.domain".as_bytes(),
&PathRule::Prefix("test".to_string()),
&MethodRule::new(None),
&Route::Cluster {
id: cluster_id1,
h2: false
}
&Route::Cluster(cluster_id1)
));

let address = SocketAddress::new_v4(127, 0, 0, 1, 1032);
Expand Down Expand Up @@ -1628,37 +1616,25 @@ mod tests {
let frontend1 = listener.frontend_from_request("lolcatho.st", "/", &Method::Get);
assert_eq!(
frontend1.expect("should find a frontend"),
Route::Cluster {
id: "cluster_1".to_string(),
h2: false
}
Route::Cluster("cluster_1".to_string())
);
println!("TEST {}", line!());
let frontend2 = listener.frontend_from_request("lolcatho.st", "/test", &Method::Get);
assert_eq!(
frontend2.expect("should find a frontend"),
Route::Cluster {
id: "cluster_1".to_string(),
h2: false
}
Route::Cluster("cluster_1".to_string())
);
println!("TEST {}", line!());
let frontend3 = listener.frontend_from_request("lolcatho.st", "/yolo/test", &Method::Get);
assert_eq!(
frontend3.expect("should find a frontend"),
Route::Cluster {
id: "cluster_2".to_string(),
h2: false
}
Route::Cluster("cluster_2".to_string())
);
println!("TEST {}", line!());
let frontend4 = listener.frontend_from_request("lolcatho.st", "/yolo/swag", &Method::Get);
assert_eq!(
frontend4.expect("should find a frontend"),
Route::Cluster {
id: "cluster_3".to_string(),
h2: false
}
Route::Cluster("cluster_3".to_string())
);
println!("TEST {}", line!());
let frontend5 = listener.frontend_from_request("domain", "/", &Method::Get);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/protocol/kawa_h1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
};

let cluster_id = match route {
Route::Cluster { id, .. } => id,
Route::Cluster(id) => id,
Route::Deny => {
self.set_answer(DefaultAnswer::Answer401 {});
return Err(RetrieveClusterError::UnauthorizedRoute);
Expand Down
20 changes: 13 additions & 7 deletions lib/src/protocol/mux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ impl<Front: SocketHandler> Connection<Front> {
timeout_container: TimeoutContainer,
) -> Connection<Front> {
Connection::H1(ConnectionH1 {
socket: front_stream,
position: Position::Server,
readiness: Readiness {
interest: Ready::READABLE | Ready::HUP | Ready::ERROR,
event: Ready::EMPTY,
},
requests: 0,
socket: front_stream,
stream: 0,
timeout_container,
})
Expand Down Expand Up @@ -667,16 +667,22 @@ impl Router {
stream.attempts += 1;

let stream_context = &mut stream.context;
let (cluster_id, h2) = self
let cluster_id = self
.route_from_request(stream_context, proxy.clone())
.map_err(BackendConnectionError::RetrieveClusterError)?;

let (frontend_should_stick, frontend_should_redirect_https) = proxy
let (frontend_should_stick, frontend_should_redirect_https, h2) = proxy
.borrow()
.clusters()
.get(&cluster_id)
.map(|cluster| (cluster.sticky_session, cluster.https_redirect))
.unwrap_or((false, false));
.map(|cluster| {
(
cluster.sticky_session,
cluster.https_redirect,
cluster.http2,
)
})
.unwrap_or((false, false, false));

if frontend_should_redirect_https && matches!(proxy.borrow().kind(), ListenerType::Http) {
return Err(BackendConnectionError::RetrieveClusterError(
Expand Down Expand Up @@ -790,7 +796,7 @@ impl Router {
&mut self,
context: &mut HttpContext,
_proxy: Rc<RefCell<dyn L7Proxy>>,
) -> Result<(String, bool), RetrieveClusterError> {
) -> Result<String, RetrieveClusterError> {
let (host, uri, method) = match context.extract_route() {
Ok(tuple) => tuple,
Err(cluster_error) => {
Expand All @@ -815,7 +821,7 @@ impl Router {
};

let cluster_id = match route {
Route::Cluster { id, h2 } => (id, h2),
Route::Cluster(id) => id,
Route::Deny => {
println!("Route::Deny");
// self.set_answer(DefaultAnswerStatus::Answer401, None);
Expand Down
Loading

0 comments on commit 00d6f96

Please sign in to comment.