feat: support hyper-rustls along with hyper v1
This commit is contained in:
parent
204a0ef195
commit
5243512f0e
4 changed files with 47 additions and 44 deletions
4
rpxy-lib/src/forwarder/cache/cache_main.rs
vendored
4
rpxy-lib/src/forwarder/cache/cache_main.rs
vendored
|
|
@ -46,6 +46,7 @@ pub(crate) struct RpxyCache {
|
|||
}
|
||||
|
||||
impl RpxyCache {
|
||||
#[allow(unused)]
|
||||
/// Generate cache storage
|
||||
pub(crate) async fn new(globals: &Globals) -> Option<Self> {
|
||||
if !globals.proxy_config.cache_enabled {
|
||||
|
|
@ -254,6 +255,7 @@ struct FileStore {
|
|||
inner: Arc<RwLock<FileStoreInner>>,
|
||||
}
|
||||
impl FileStore {
|
||||
#[allow(unused)]
|
||||
/// Build manager
|
||||
async fn new(runtime_handle: &tokio::runtime::Handle) -> Self {
|
||||
Self {
|
||||
|
|
@ -300,6 +302,7 @@ struct FileStoreInner {
|
|||
}
|
||||
|
||||
impl FileStoreInner {
|
||||
#[allow(unused)]
|
||||
/// Build new cache file manager.
|
||||
/// This first creates cache file dir if not exists, and cleans up the file inside the directory.
|
||||
/// TODO: Persistent cache is really difficult. `sqlite` or something like that is needed.
|
||||
|
|
@ -436,6 +439,7 @@ struct LruCacheManager {
|
|||
}
|
||||
|
||||
impl LruCacheManager {
|
||||
#[allow(unused)]
|
||||
/// Build LruCache
|
||||
fn new(cache_max_entry: usize) -> Self {
|
||||
Self {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#[allow(unused)]
|
||||
use crate::{
|
||||
error::{RpxyError, RpxyResult},
|
||||
globals::Globals,
|
||||
|
|
@ -192,7 +193,7 @@ where
|
|||
|
||||
#[cfg(feature = "rustls-backend")]
|
||||
/// Build forwarder with hyper-rustls (rustls)
|
||||
impl<B1> Forwarder<HttpConnector, B1>
|
||||
impl<B1> Forwarder<hyper_rustls::HttpsConnector<HttpConnector>, B1>
|
||||
where
|
||||
B1: Body + Send + Unpin + 'static,
|
||||
<B1 as Body>::Data: Send,
|
||||
|
|
@ -200,26 +201,32 @@ where
|
|||
{
|
||||
/// Build forwarder
|
||||
pub async fn try_new(_globals: &Arc<Globals>) -> RpxyResult<Self> {
|
||||
todo!("Not implemented yet. Please use native-tls-backend feature for now.");
|
||||
// #[cfg(feature = "native-roots")]
|
||||
// let builder = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots();
|
||||
// #[cfg(feature = "native-roots")]
|
||||
// let builder_h2 = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots();
|
||||
// #[cfg(feature = "native-roots")]
|
||||
// info!("Native cert store is used for the connection to backend applications");
|
||||
// build hyper client with rustls and webpki, only https is allowed
|
||||
#[cfg(feature = "rustls-backend-webpki")]
|
||||
let builder = hyper_rustls::HttpsConnectorBuilder::new().with_webpki_roots();
|
||||
#[cfg(feature = "rustls-backend-webpki")]
|
||||
let builder_h2 = hyper_rustls::HttpsConnectorBuilder::new().with_webpki_roots();
|
||||
#[cfg(feature = "rustls-backend-webpki")]
|
||||
info!("Mozilla WebPKI root certs with rustls is used for the connection to backend applications");
|
||||
|
||||
// #[cfg(not(feature = "native-roots"))]
|
||||
// let builder = hyper_rustls::HttpsConnectorBuilder::new().with_webpki_roots();
|
||||
// #[cfg(not(feature = "native-roots"))]
|
||||
// let builder_h2 = hyper_rustls::HttpsConnectorBuilder::new().with_webpki_roots();
|
||||
// #[cfg(not(feature = "native-roots"))]
|
||||
// info!("Mozilla WebPKI root certs is used for the connection to backend applications");
|
||||
#[cfg(not(feature = "rustls-backend-webpki"))]
|
||||
let builder = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots()?;
|
||||
#[cfg(not(feature = "rustls-backend-webpki"))]
|
||||
let builder_h2 = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots()?;
|
||||
#[cfg(not(feature = "rustls-backend-webpki"))]
|
||||
info!("Native cert store with rustls is used for the connection to backend applications");
|
||||
|
||||
// let connector = builder.https_or_http().enable_http1().enable_http2().build();
|
||||
// let connector_h2 = builder_h2.https_or_http().enable_http2().build();
|
||||
let connector = builder.https_or_http().enable_all_versions().build();
|
||||
let connector_h2 = builder_h2.https_or_http().enable_http2().build();
|
||||
let inner = Client::builder(LocalExecutor::new(_globals.runtime_handle.clone())).build::<_, B1>(connector);
|
||||
let inner_h2 = Client::builder(LocalExecutor::new(_globals.runtime_handle.clone())).build::<_, B1>(connector_h2);
|
||||
|
||||
// let inner = Client::builder().build::<_, Body>(connector);
|
||||
// let inner_h2 = Client::builder().http2_only(true).build::<_, Body>(connector_h2);
|
||||
Ok(Self {
|
||||
inner,
|
||||
inner_h2,
|
||||
#[cfg(feature = "cache")]
|
||||
cache: RpxyCache::new(_globals).await,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue