This commit is contained in:
Jun Kurihara 2022-07-27 22:21:42 +09:00
commit d750f87331
No known key found for this signature in database
GPG key ID: 48ADFD173ED22B03
4 changed files with 6 additions and 5 deletions

View file

@ -17,7 +17,8 @@ use tokio_rustls::rustls::{
pub use upstream::{ReverseProxy, Upstream, UpstreamGroup};
pub use upstream_opts::UpstreamOption;
// server name (hostname or ip address) and path name representation in backends
// Server name (hostname or ip address) and path name representation in backends
// For searching hashmap or key list by exact or longest-prefix matching
pub type ServerNameExp = Vec<u8>; // lowercase ascii bytes
pub type PathNameExp = Vec<u8>; // lowercase ascii bytes
@ -111,7 +112,7 @@ impl Backend {
/// HashMap and some meta information for multiple Backend structs.
pub struct Backends {
pub apps: HashMap<ServerNameExp, Backend>, // hyper::uriで抜いたhostで引っ掛ける
pub default_server_name: Option<ServerNameExp>, // for plaintext http
pub default_server_name_bytes: Option<ServerNameExp>, // for plaintext http
}
impl Backends {

View file

@ -150,7 +150,7 @@ pub fn parse_opts(globals: &mut Globals) -> std::result::Result<(), anyhow::Erro
"Serving plaintext http for requests to unconfigured server_name by app {} (server_name: {}).",
d, d_sn[0]
);
globals.backends.default_server_name = Some(d_sn[0].as_bytes().to_vec());
globals.backends.default_server_name_bytes = Some(d_sn[0].as_bytes().to_vec());
}
}

View file

@ -62,7 +62,7 @@ where
// Find backend application for given server_name, and drop if incoming request is invalid as request.
let backend = if let Some(be) = self.globals.backends.apps.get(&server_name_bytes) {
be
} else if let Some(default_server_name) = &self.globals.backends.default_server_name {
} else if let Some(default_server_name) = &self.globals.backends.default_server_name_bytes {
debug!("Serving by default app");
self.globals.backends.apps.get(default_server_name).unwrap()
} else {

View file

@ -71,7 +71,7 @@ fn main() {
runtime_handle: runtime.handle().clone(),
backends: Backends {
default_server_name: None,
default_server_name_bytes: None,
apps: HashMap::<ServerNameExp, Backend>::default(),
},