Skip to content

Commit 00d6f96

Browse files
committed
don't push
Signed-off-by: Eloi DEMOLIS <eloi.demolis@clever-cloud.com>
1 parent 96b2b9f commit 00d6f96

File tree

10 files changed

+61
-175
lines changed

10 files changed

+61
-175
lines changed

bin/src/ctl/request_builder.rs

-2
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ impl CommandManager {
251251
Some(tags) => tags,
252252
None => BTreeMap::new(),
253253
},
254-
h2: h2.unwrap_or(false),
255254
})
256255
.into(),
257256
),
@@ -301,7 +300,6 @@ impl CommandManager {
301300
Some(tags) => tags,
302301
None => BTreeMap::new(),
303302
},
304-
h2: h2.unwrap_or(false),
305303
})
306304
.into(),
307305
),

command/src/command.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ message RequestHttpFrontend {
248248
required RulePosition position = 6 [default = TREE];
249249
// custom tags to identify the frontend in the access logs
250250
map<string, string> tags = 7;
251-
required bool h2 = 8;
252251
}
253252

254253
message RequestTcpFrontend {
@@ -383,6 +382,7 @@ message Cluster {
383382
required LoadBalancingAlgorithms load_balancing = 5 [default = ROUND_ROBIN];
384383
optional string answer_503 = 6;
385384
optional LoadMetric load_metric = 7;
385+
required bool http2 = 8;
386386
}
387387

388388
enum LoadBalancingAlgorithms {

command/src/config.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,6 @@ pub struct FileClusterFrontendConfig {
681681
#[serde(default = "default_rule_position")]
682682
pub position: RulePosition,
683683
pub tags: Option<BTreeMap<String, String>>,
684-
pub h2: Option<bool>,
685684
}
686685

687686
impl FileClusterFrontendConfig {
@@ -767,7 +766,6 @@ impl FileClusterFrontendConfig {
767766
path,
768767
method: self.method.clone(),
769768
tags: self.tags.clone(),
770-
h2: self.h2.unwrap_or(false),
771769
})
772770
}
773771
}
@@ -784,6 +782,7 @@ pub enum ListenerProtocol {
784782
#[serde(deny_unknown_fields, rename_all = "lowercase")]
785783
pub enum FileClusterProtocolConfig {
786784
Http,
785+
Http2,
787786
Tcp,
788787
}
789788

@@ -873,7 +872,7 @@ impl FileClusterConfig {
873872
load_metric: self.load_metric,
874873
}))
875874
}
876-
FileClusterProtocolConfig::Http => {
875+
FileClusterProtocolConfig::Http | FileClusterProtocolConfig::Http2 => {
877876
let mut frontends = Vec::new();
878877
for frontend in self.frontends {
879878
let http_frontend = frontend.to_http_front(cluster_id)?;
@@ -891,6 +890,7 @@ impl FileClusterConfig {
891890

892891
Ok(ClusterConfig::Http(HttpClusterConfig {
893892
cluster_id: cluster_id.to_string(),
893+
http2: self.protocol == FileClusterProtocolConfig::Http2,
894894
frontends,
895895
backends: self.backends,
896896
sticky_session: self.sticky_session.unwrap_or(false),
@@ -919,7 +919,6 @@ pub struct HttpFrontendConfig {
919919
#[serde(default)]
920920
pub position: RulePosition,
921921
pub tags: Option<BTreeMap<String, String>>,
922-
pub h2: bool,
923922
}
924923

925924
impl HttpFrontendConfig {
@@ -955,7 +954,6 @@ impl HttpFrontendConfig {
955954
path: self.path.clone(),
956955
method: self.method.clone(),
957956
position: self.position.into(),
958-
h2: self.h2,
959957
tags,
960958
})
961959
.into(),
@@ -970,7 +968,6 @@ impl HttpFrontendConfig {
970968
path: self.path.clone(),
971969
method: self.method.clone(),
972970
position: self.position.into(),
973-
h2: self.h2,
974971
tags,
975972
})
976973
.into(),
@@ -985,6 +982,7 @@ impl HttpFrontendConfig {
985982
#[serde(deny_unknown_fields)]
986983
pub struct HttpClusterConfig {
987984
pub cluster_id: String,
985+
pub http2: bool,
988986
pub frontends: Vec<HttpFrontendConfig>,
989987
pub backends: Vec<BackendConfig>,
990988
pub sticky_session: bool,
@@ -1000,6 +998,7 @@ impl HttpClusterConfig {
1000998
cluster_id: self.cluster_id.clone(),
1001999
sticky_session: self.sticky_session,
10021000
https_redirect: self.https_redirect,
1001+
http2: self.http2,
10031002
proxy_protocol: None,
10041003
load_balancing: self.load_balancing as i32,
10051004
answer_503: self.answer_503.clone(),
@@ -1059,6 +1058,7 @@ impl TcpClusterConfig {
10591058
cluster_id: self.cluster_id.clone(),
10601059
sticky_session: false,
10611060
https_redirect: false,
1061+
http2: false,
10621062
proxy_protocol: self.proxy_protocol.map(|s| s as i32),
10631063
load_balancing: self.load_balancing as i32,
10641064
load_metric: self.load_metric.map(|s| s as i32),

command/src/request.rs

-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ impl RequestHttpFrontend {
173173
}
174174
})?,
175175
tags: Some(self.tags),
176-
h2: self.h2,
177176
})
178177
}
179178
}

command/src/response.rs

-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ pub struct HttpFrontend {
3939
#[serde(default)]
4040
pub position: RulePosition,
4141
pub tags: Option<BTreeMap<String, String>>,
42-
pub h2: bool,
4342
}
4443

4544
impl From<HttpFrontend> for RequestHttpFrontend {
@@ -55,7 +54,6 @@ impl From<HttpFrontend> for RequestHttpFrontend {
5554
path: val.path,
5655
method: val.method,
5756
position: val.position.into(),
58-
h2: val.h2,
5957
tags,
6058
}
6159
}

lib/src/http.rs

+5-21
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ impl L7ListenerHandler for HttpListener {
520520

521521
let now = Instant::now();
522522

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

@@ -1374,7 +1374,6 @@ mod tests {
13741374
position: RulePosition::Tree,
13751375
cluster_id: Some(cluster_id1),
13761376
tags: None,
1377-
h2: false,
13781377
})
13791378
.expect("Could not add http frontend");
13801379
fronts
@@ -1386,7 +1385,6 @@ mod tests {
13861385
position: RulePosition::Tree,
13871386
cluster_id: Some(cluster_id2),
13881387
tags: None,
1389-
h2: false,
13901388
})
13911389
.expect("Could not add http frontend");
13921390
fronts
@@ -1398,7 +1396,6 @@ mod tests {
13981396
position: RulePosition::Tree,
13991397
cluster_id: Some(cluster_id3),
14001398
tags: None,
1401-
h2: false,
14021399
})
14031400
.expect("Could not add http frontend");
14041401
fronts
@@ -1410,7 +1407,6 @@ mod tests {
14101407
position: RulePosition::Tree,
14111408
cluster_id: Some("cluster_1".to_owned()),
14121409
tags: None,
1413-
h2: false,
14141410
})
14151411
.expect("Could not add http frontend");
14161412

@@ -1440,31 +1436,19 @@ mod tests {
14401436
let frontend5 = listener.frontend_from_request("domain", "/", &Method::Get);
14411437
assert_eq!(
14421438
frontend1.expect("should find frontend"),
1443-
Route::Cluster {
1444-
id: "cluster_1".to_string(),
1445-
h2: false
1446-
}
1439+
Route::Cluster("cluster_1".to_string())
14471440
);
14481441
assert_eq!(
14491442
frontend2.expect("should find frontend"),
1450-
Route::Cluster {
1451-
id: "cluster_1".to_string(),
1452-
h2: false
1453-
}
1443+
Route::Cluster("cluster_1".to_string())
14541444
);
14551445
assert_eq!(
14561446
frontend3.expect("should find frontend"),
1457-
Route::Cluster {
1458-
id: "cluster_2".to_string(),
1459-
h2: false
1460-
}
1447+
Route::Cluster("cluster_2".to_string())
14611448
);
14621449
assert_eq!(
14631450
frontend4.expect("should find frontend"),
1464-
Route::Cluster {
1465-
id: "cluster_3".to_string(),
1466-
h2: false
1467-
}
1451+
Route::Cluster("cluster_3".to_string())
14681452
);
14691453
assert!(frontend5.is_err());
14701454
}

lib/src/https.rs

+9-33
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ impl L7ListenerHandler for HttpsListener {
606606

607607
let now = Instant::now();
608608

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

@@ -1557,37 +1557,25 @@ mod tests {
15571557
"lolcatho.st".as_bytes(),
15581558
&PathRule::Prefix(uri1),
15591559
&MethodRule::new(None),
1560-
&Route::Cluster {
1561-
id: cluster_id1.clone(),
1562-
h2: false
1563-
}
1560+
&Route::Cluster(cluster_id1.clone())
15641561
));
15651562
assert!(fronts.add_tree_rule(
15661563
"lolcatho.st".as_bytes(),
15671564
&PathRule::Prefix(uri2),
15681565
&MethodRule::new(None),
1569-
&Route::Cluster {
1570-
id: cluster_id2,
1571-
h2: false
1572-
}
1566+
&Route::Cluster(cluster_id2)
15731567
));
15741568
assert!(fronts.add_tree_rule(
15751569
"lolcatho.st".as_bytes(),
15761570
&PathRule::Prefix(uri3),
15771571
&MethodRule::new(None),
1578-
&Route::Cluster {
1579-
id: cluster_id3,
1580-
h2: false
1581-
}
1572+
&Route::Cluster(cluster_id3)
15821573
));
15831574
assert!(fronts.add_tree_rule(
15841575
"other.domain".as_bytes(),
15851576
&PathRule::Prefix("test".to_string()),
15861577
&MethodRule::new(None),
1587-
&Route::Cluster {
1588-
id: cluster_id1,
1589-
h2: false
1590-
}
1578+
&Route::Cluster(cluster_id1)
15911579
));
15921580

15931581
let address = SocketAddress::new_v4(127, 0, 0, 1, 1032);
@@ -1628,37 +1616,25 @@ mod tests {
16281616
let frontend1 = listener.frontend_from_request("lolcatho.st", "/", &Method::Get);
16291617
assert_eq!(
16301618
frontend1.expect("should find a frontend"),
1631-
Route::Cluster {
1632-
id: "cluster_1".to_string(),
1633-
h2: false
1634-
}
1619+
Route::Cluster("cluster_1".to_string())
16351620
);
16361621
println!("TEST {}", line!());
16371622
let frontend2 = listener.frontend_from_request("lolcatho.st", "/test", &Method::Get);
16381623
assert_eq!(
16391624
frontend2.expect("should find a frontend"),
1640-
Route::Cluster {
1641-
id: "cluster_1".to_string(),
1642-
h2: false
1643-
}
1625+
Route::Cluster("cluster_1".to_string())
16441626
);
16451627
println!("TEST {}", line!());
16461628
let frontend3 = listener.frontend_from_request("lolcatho.st", "/yolo/test", &Method::Get);
16471629
assert_eq!(
16481630
frontend3.expect("should find a frontend"),
1649-
Route::Cluster {
1650-
id: "cluster_2".to_string(),
1651-
h2: false
1652-
}
1631+
Route::Cluster("cluster_2".to_string())
16531632
);
16541633
println!("TEST {}", line!());
16551634
let frontend4 = listener.frontend_from_request("lolcatho.st", "/yolo/swag", &Method::Get);
16561635
assert_eq!(
16571636
frontend4.expect("should find a frontend"),
1658-
Route::Cluster {
1659-
id: "cluster_3".to_string(),
1660-
h2: false
1661-
}
1637+
Route::Cluster("cluster_3".to_string())
16621638
);
16631639
println!("TEST {}", line!());
16641640
let frontend5 = listener.frontend_from_request("domain", "/", &Method::Get);

lib/src/protocol/kawa_h1/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ impl<Front: SocketHandler, L: ListenerHandler + L7ListenerHandler> Http<Front, L
11991199
};
12001200

12011201
let cluster_id = match route {
1202-
Route::Cluster { id, .. } => id,
1202+
Route::Cluster(id) => id,
12031203
Route::Deny => {
12041204
self.set_answer(DefaultAnswer::Answer401 {});
12051205
return Err(RetrieveClusterError::UnauthorizedRoute);

lib/src/protocol/mux/mod.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,13 @@ impl<Front: SocketHandler> Connection<Front> {
184184
timeout_container: TimeoutContainer,
185185
) -> Connection<Front> {
186186
Connection::H1(ConnectionH1 {
187+
socket: front_stream,
187188
position: Position::Server,
188189
readiness: Readiness {
189190
interest: Ready::READABLE | Ready::HUP | Ready::ERROR,
190191
event: Ready::EMPTY,
191192
},
192193
requests: 0,
193-
socket: front_stream,
194194
stream: 0,
195195
timeout_container,
196196
})
@@ -667,16 +667,22 @@ impl Router {
667667
stream.attempts += 1;
668668

669669
let stream_context = &mut stream.context;
670-
let (cluster_id, h2) = self
670+
let cluster_id = self
671671
.route_from_request(stream_context, proxy.clone())
672672
.map_err(BackendConnectionError::RetrieveClusterError)?;
673673

674-
let (frontend_should_stick, frontend_should_redirect_https) = proxy
674+
let (frontend_should_stick, frontend_should_redirect_https, h2) = proxy
675675
.borrow()
676676
.clusters()
677677
.get(&cluster_id)
678-
.map(|cluster| (cluster.sticky_session, cluster.https_redirect))
679-
.unwrap_or((false, false));
678+
.map(|cluster| {
679+
(
680+
cluster.sticky_session,
681+
cluster.https_redirect,
682+
cluster.http2,
683+
)
684+
})
685+
.unwrap_or((false, false, false));
680686

681687
if frontend_should_redirect_https && matches!(proxy.borrow().kind(), ListenerType::Http) {
682688
return Err(BackendConnectionError::RetrieveClusterError(
@@ -790,7 +796,7 @@ impl Router {
790796
&mut self,
791797
context: &mut HttpContext,
792798
_proxy: Rc<RefCell<dyn L7Proxy>>,
793-
) -> Result<(String, bool), RetrieveClusterError> {
799+
) -> Result<String, RetrieveClusterError> {
794800
let (host, uri, method) = match context.extract_route() {
795801
Ok(tuple) => tuple,
796802
Err(cluster_error) => {
@@ -815,7 +821,7 @@ impl Router {
815821
};
816822

817823
let cluster_id = match route {
818-
Route::Cluster { id, h2 } => (id, h2),
824+
Route::Cluster(id) => id,
819825
Route::Deny => {
820826
println!("Route::Deny");
821827
// self.set_answer(DefaultAnswerStatus::Answer401, None);

0 commit comments

Comments
 (0)