refactor
This commit is contained in:
parent
f77ce38e51
commit
d750f87331
4 changed files with 6 additions and 5 deletions
|
|
@ -17,7 +17,8 @@ use tokio_rustls::rustls::{
|
||||||
pub use upstream::{ReverseProxy, Upstream, UpstreamGroup};
|
pub use upstream::{ReverseProxy, Upstream, UpstreamGroup};
|
||||||
pub use upstream_opts::UpstreamOption;
|
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 ServerNameExp = Vec<u8>; // lowercase ascii bytes
|
||||||
pub type PathNameExp = 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.
|
/// HashMap and some meta information for multiple Backend structs.
|
||||||
pub struct Backends {
|
pub struct Backends {
|
||||||
pub apps: HashMap<ServerNameExp, Backend>, // hyper::uriで抜いたhostで引っ掛ける
|
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 {
|
impl Backends {
|
||||||
|
|
|
||||||
|
|
@ -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: {}).",
|
"Serving plaintext http for requests to unconfigured server_name by app {} (server_name: {}).",
|
||||||
d, d_sn[0]
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ where
|
||||||
// Find backend application for given server_name, and drop if incoming request is invalid as request.
|
// 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) {
|
let backend = if let Some(be) = self.globals.backends.apps.get(&server_name_bytes) {
|
||||||
be
|
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");
|
debug!("Serving by default app");
|
||||||
self.globals.backends.apps.get(default_server_name).unwrap()
|
self.globals.backends.apps.get(default_server_name).unwrap()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ fn main() {
|
||||||
|
|
||||||
runtime_handle: runtime.handle().clone(),
|
runtime_handle: runtime.handle().clone(),
|
||||||
backends: Backends {
|
backends: Backends {
|
||||||
default_server_name: None,
|
default_server_name_bytes: None,
|
||||||
apps: HashMap::<ServerNameExp, Backend>::default(),
|
apps: HashMap::<ServerNameExp, Backend>::default(),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue