Skip to content

Commit f1b82f5

Browse files
committed
feat(client): use sni in connection key for pool
1 parent eaa5fd4 commit f1b82f5

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

client/src/connection.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use core::hash::{Hash, Hasher};
22

33
use xitca_http::http::uri::{Authority, PathAndQuery};
44

5-
use super::{tls::TlsStream, uri::Uri};
5+
use super::{connect::Connect, tls::TlsStream, uri::Uri};
66

77
#[cfg(feature = "http1")]
88
/// A convince type alias for typing connection without interacting with pool.
@@ -42,10 +42,17 @@ impl From<crate::h3::Connection> for ConnectionShared {
4242
#[doc(hidden)]
4343
#[derive(PartialEq, Eq, Debug, Clone, Hash)]
4444
pub enum ConnectionKey {
45-
Regular(Authority),
45+
Regular(AuthorityWithSni),
4646
Unix(AuthorityWithPath),
4747
}
4848

49+
#[doc(hidden)]
50+
#[derive(PartialEq, Eq, Debug, Clone, Hash)]
51+
pub struct AuthorityWithSni {
52+
authority: Authority,
53+
sni: Option<String>,
54+
}
55+
4956
#[doc(hidden)]
5057
#[derive(Eq, Debug, Clone)]
5158
pub struct AuthorityWithPath {
@@ -66,10 +73,13 @@ impl Hash for AuthorityWithPath {
6673
}
6774
}
6875

69-
impl From<&Uri<'_>> for ConnectionKey {
70-
fn from(uri: &Uri<'_>) -> Self {
71-
match *uri {
72-
Uri::Tcp(uri) | Uri::Tls(uri) => ConnectionKey::Regular(uri.authority().unwrap().clone()),
76+
impl From<&Connect<'_>> for ConnectionKey {
77+
fn from(connect: &Connect<'_>) -> Self {
78+
match connect.uri {
79+
Uri::Tcp(uri) | Uri::Tls(uri) => ConnectionKey::Regular(AuthorityWithSni {
80+
authority: uri.authority().unwrap().clone(),
81+
sni: connect.sni_hostname.map(|s| s.to_string()),
82+
}),
7383
Uri::Unix(uri) => ConnectionKey::Unix(AuthorityWithPath {
7484
authority: uri.authority().unwrap().clone(),
7585
path_and_query: uri.path_and_query().unwrap().clone(),

client/src/service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub(crate) fn base_service() -> HttpService {
106106

107107
loop {
108108
match version {
109-
Version::HTTP_2 | Version::HTTP_3 => match client.shared_pool.acquire(&connect.uri).await {
109+
Version::HTTP_2 | Version::HTTP_3 => match client.shared_pool.acquire(&connect).await {
110110
shared::AcquireOutput::Conn(mut _conn) => {
111111
let mut _timer = Box::pin(tokio::time::sleep(timeout));
112112
*req.version_mut() = version;
@@ -203,7 +203,7 @@ pub(crate) fn base_service() -> HttpService {
203203

204204
#[cfg(feature = "http1")]
205205
{
206-
client.exclusive_pool.try_add(&connect.uri, conn);
206+
client.exclusive_pool.try_add(&connect, conn);
207207
// downgrade request version to what alpn protocol suggested from make_exclusive.
208208
version = alpn_version;
209209
}
@@ -218,7 +218,7 @@ pub(crate) fn base_service() -> HttpService {
218218
_ => unreachable!("outer match didn't handle version correctly."),
219219
},
220220
},
221-
version => match client.exclusive_pool.acquire(&connect.uri).await {
221+
version => match client.exclusive_pool.acquire(&connect).await {
222222
exclusive::AcquireOutput::Conn(mut _conn) => {
223223
*req.version_mut() = version;
224224

0 commit comments

Comments
 (0)