refactor
This commit is contained in:
parent
6f05da8620
commit
ec56072a39
4 changed files with 19 additions and 17 deletions
|
|
@ -53,6 +53,7 @@ h3 = { git = "https://github.com/hyperium/h3.git" }
|
|||
h3-quinn = { git = "https://github.com/hyperium/h3.git" }
|
||||
bytes = "1.1.0"
|
||||
mimalloc-rust = "0.2.0"
|
||||
thiserror = "1.0.31"
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
13
src/error.rs
13
src/error.rs
|
|
@ -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,
|
||||
// }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue