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

@ -53,6 +53,7 @@ h3 = { git = "https://github.com/hyperium/h3.git" }
h3-quinn = { git = "https://github.com/hyperium/h3.git" } h3-quinn = { git = "https://github.com/hyperium/h3.git" }
bytes = "1.1.0" bytes = "1.1.0"
mimalloc-rust = "0.2.0" mimalloc-rust = "0.2.0"
thiserror = "1.0.31"
[dev-dependencies] [dev-dependencies]

View file

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

View file

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

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,
// }