wip: support rustls-0.23 for http1.1 and 1.2
This commit is contained in:
parent
2f9f0a1122
commit
0c6f3edf18
16 changed files with 80 additions and 393 deletions
|
|
@ -1,5 +1,4 @@
|
|||
use crate::{
|
||||
crypto::CryptoSource,
|
||||
error::*,
|
||||
log::*,
|
||||
name_exp::{ByteName, ServerName},
|
||||
|
|
@ -13,10 +12,7 @@ use super::upstream::PathManager;
|
|||
|
||||
/// Struct serving information to route incoming connections, like server name to be handled and tls certs/keys settings.
|
||||
#[derive(Builder)]
|
||||
pub struct BackendApp<T>
|
||||
where
|
||||
T: CryptoSource,
|
||||
{
|
||||
pub struct BackendApp {
|
||||
#[builder(setter(into))]
|
||||
/// backend application name, e.g., app1
|
||||
pub app_name: String,
|
||||
|
|
@ -28,50 +24,27 @@ where
|
|||
/// tls settings: https redirection with 30x
|
||||
#[builder(default)]
|
||||
pub https_redirection: Option<bool>,
|
||||
/// TLS settings: source meta for server cert, key, client ca cert
|
||||
#[builder(default)]
|
||||
pub crypto_source: Option<T>,
|
||||
}
|
||||
impl<'a, T> BackendAppBuilder<T>
|
||||
where
|
||||
T: CryptoSource,
|
||||
{
|
||||
impl<'a> BackendAppBuilder {
|
||||
pub fn server_name(&mut self, server_name: impl Into<Cow<'a, str>>) -> &mut Self {
|
||||
self.server_name = Some(server_name.to_server_name());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
/// HashMap and some meta information for multiple Backend structs.
|
||||
pub struct BackendAppManager<T>
|
||||
where
|
||||
T: CryptoSource,
|
||||
{
|
||||
pub struct BackendAppManager {
|
||||
/// HashMap of Backend structs, key is server name
|
||||
pub apps: HashMap<ServerName, BackendApp<T>>,
|
||||
pub apps: HashMap<ServerName, BackendApp>,
|
||||
/// for plaintext http
|
||||
pub default_server_name: Option<ServerName>,
|
||||
}
|
||||
|
||||
impl<T> Default for BackendAppManager<T>
|
||||
where
|
||||
T: CryptoSource,
|
||||
{
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
apps: HashMap::<ServerName, BackendApp<T>>::default(),
|
||||
default_server_name: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> TryFrom<&AppConfig<T>> for BackendApp<T>
|
||||
where
|
||||
T: CryptoSource + Clone,
|
||||
{
|
||||
impl TryFrom<&AppConfig> for BackendApp {
|
||||
type Error = RpxyError;
|
||||
|
||||
fn try_from(app_config: &AppConfig<T>) -> Result<Self, Self::Error> {
|
||||
fn try_from(app_config: &AppConfig) -> Result<Self, Self::Error> {
|
||||
let mut backend_builder = BackendAppBuilder::default();
|
||||
let path_manager = PathManager::try_from(app_config)?;
|
||||
backend_builder
|
||||
|
|
@ -83,28 +56,20 @@ where
|
|||
backend_builder.build()?
|
||||
} else {
|
||||
let tls = app_config.tls.as_ref().unwrap();
|
||||
backend_builder
|
||||
.https_redirection(Some(tls.https_redirection))
|
||||
.crypto_source(Some(tls.inner.clone()))
|
||||
.build()?
|
||||
backend_builder.https_redirection(Some(tls.https_redirection)).build()?
|
||||
};
|
||||
Ok(backend)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> TryFrom<&AppConfigList<T>> for BackendAppManager<T>
|
||||
where
|
||||
T: CryptoSource + Clone,
|
||||
{
|
||||
impl TryFrom<&AppConfigList> for BackendAppManager {
|
||||
type Error = RpxyError;
|
||||
|
||||
fn try_from(config_list: &AppConfigList<T>) -> Result<Self, Self::Error> {
|
||||
fn try_from(config_list: &AppConfigList) -> Result<Self, Self::Error> {
|
||||
let mut manager = Self::default();
|
||||
for app_config in config_list.inner.iter() {
|
||||
let backend: BackendApp<T> = BackendApp::try_from(app_config)?;
|
||||
manager
|
||||
.apps
|
||||
.insert(app_config.server_name.clone().to_server_name(), backend);
|
||||
let backend: BackendApp = BackendApp::try_from(app_config)?;
|
||||
manager.apps.insert(app_config.server_name.clone().to_server_name(), backend);
|
||||
|
||||
info!(
|
||||
"Registering application {} ({})",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue