This commit is contained in:
Jun Kurihara 2022-07-11 23:23:55 +09:00
commit ec56072a39
No known key found for this signature in database
GPG key ID: 48ADFD173ED22B03
4 changed files with 19 additions and 17 deletions

View file

@ -18,7 +18,7 @@ pub type ServerNameLC = Vec<u8>;
pub type PathNameLC = Vec<u8>;
pub struct Backends {
pub apps: HashMap<ServerNameLC, Backend>, // TODO: hyper::uriで抜いたhostで引っ掛ける。Stringでいいのか
pub apps: HashMap<ServerNameLC, Backend>, // hyper::uriで抜いたhostで引っ掛ける
pub default_server_name: Option<ServerNameLC>, // for plaintext http
}
@ -35,7 +35,7 @@ pub struct Backend {
#[derive(Debug, Clone)]
pub struct ReverseProxy {
pub upstream: HashMap<PathNameLC, Upstream>,
pub upstream: HashMap<PathNameLC, Upstream>, // TODO: HashMapでいいのかは疑問。max_by_keyでlongest prefix matchしてるのも無駄っぽいが。。。
}
impl ReverseProxy {
@ -182,12 +182,7 @@ impl Backend {
)
})?;
reader.set_position(0);
let mut rsa_keys = rustls_pemfile::rsa_private_keys(&mut reader).map_err(|_| {
io::Error::new(
io::ErrorKind::InvalidInput,
"Unable to parse the certificates private keys (RSA)",
)
})?;
let mut rsa_keys = rustls_pemfile::rsa_private_keys(&mut reader)?;
let mut keys = pkcs8_keys;
keys.append(&mut rsa_keys);
if keys.is_empty() {

View file

@ -64,13 +64,8 @@ impl UpstreamParams {
impl ConfigToml {
pub fn new(config_file: &str) -> Result<Self> {
let config_str = if let Ok(s) = fs::read_to_string(config_file) {
s
} else {
bail!("Failed to read config file");
};
let parsed: Result<ConfigToml> = toml::from_str(&config_str)
.map_err(|e: toml::de::Error| anyhow!("Failed to parse toml config: {:?}", e));
parsed
let config_str = fs::read_to_string(config_file).context("Failed to read config file")?;
toml::from_str(&config_str).context("Failed to parse toml config")
}
}

View file

@ -1 +1,12 @@
pub use anyhow::{anyhow, bail, ensure, Context, Error, Result};
pub use anyhow::{anyhow, bail, ensure, Context, Result};
// use thiserror::Error;
// #[allow(clippy::enum_variant_names)]
// #[derive(Debug, Error)]
// pub enum RpxyError {
// // IoError,
// #[error("ConfigError: {0}")]
// ConfigError(String),
// // ConnectionError,
// // HttpError,
// }