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
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "rpxy"
|
name = "rpxy"
|
||||||
version = "0.7.0-alpha.1"
|
version = "0.7.0-alpha.2"
|
||||||
authors = ["Jun Kurihara"]
|
authors = ["Jun Kurihara"]
|
||||||
homepage = "https://github.com/junkurihara/rust-rpxy"
|
homepage = "https://github.com/junkurihara/rust-rpxy"
|
||||||
repository = "https://github.com/junkurihara/rust-rpxy"
|
repository = "https://github.com/junkurihara/rust-rpxy"
|
||||||
|
|
@ -12,14 +12,13 @@ publish = false
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["http3-quinn", "cache", "native-tls-backend"]
|
default = ["http3-quinn", "cache", "rustls-backend"]
|
||||||
http3-quinn = ["rpxy-lib/http3-quinn"]
|
http3-quinn = ["rpxy-lib/http3-quinn"]
|
||||||
http3-s2n = ["rpxy-lib/http3-s2n"]
|
http3-s2n = ["rpxy-lib/http3-s2n"]
|
||||||
native-tls-backend = ["rpxy-lib/native-tls-backend"]
|
native-tls-backend = ["rpxy-lib/native-tls-backend"]
|
||||||
# Not yet implemented
|
|
||||||
rustls-backend = ["rpxy-lib/rustls-backend"]
|
rustls-backend = ["rpxy-lib/rustls-backend"]
|
||||||
|
rustls-backend-webpki = ["rpxy-lib/rustls-backend-webpki"]
|
||||||
cache = ["rpxy-lib/cache"]
|
cache = ["rpxy-lib/cache"]
|
||||||
native-roots = ["rpxy-lib/native-roots"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rpxy-lib = { path = "../rpxy-lib/", default-features = false, features = [
|
rpxy-lib = { path = "../rpxy-lib/", default-features = false, features = [
|
||||||
|
|
@ -42,7 +41,7 @@ rustls-pemfile = "1.0.4"
|
||||||
mimalloc = { version = "*", default-features = false }
|
mimalloc = { version = "*", default-features = false }
|
||||||
|
|
||||||
# config
|
# config
|
||||||
clap = { version = "4.4.14", features = ["std", "cargo", "wrap_help"] }
|
clap = { version = "4.4.16", features = ["std", "cargo", "wrap_help"] }
|
||||||
toml = { version = "0.8.8", default-features = false, features = ["parse"] }
|
toml = { version = "0.8.8", default-features = false, features = ["parse"] }
|
||||||
hot_reload = "0.1.4"
|
hot_reload = "0.1.4"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "rpxy-lib"
|
name = "rpxy-lib"
|
||||||
version = "0.7.0-alpha.1"
|
version = "0.7.0-alpha.2"
|
||||||
authors = ["Jun Kurihara"]
|
authors = ["Jun Kurihara"]
|
||||||
homepage = "https://github.com/junkurihara/rust-rpxy"
|
homepage = "https://github.com/junkurihara/rust-rpxy"
|
||||||
repository = "https://github.com/junkurihara/rust-rpxy"
|
repository = "https://github.com/junkurihara/rust-rpxy"
|
||||||
|
|
@ -12,7 +12,7 @@ publish = false
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["http3-quinn", "sticky-cookie", "cache", "native-tls-backend"]
|
default = ["http3-quinn", "sticky-cookie", "cache", "rustls-backend"]
|
||||||
http3-quinn = ["socket2", "quinn", "h3", "h3-quinn"]
|
http3-quinn = ["socket2", "quinn", "h3", "h3-quinn"]
|
||||||
http3-s2n = [
|
http3-s2n = [
|
||||||
"h3",
|
"h3",
|
||||||
|
|
@ -24,8 +24,8 @@ http3-s2n = [
|
||||||
cache = ["http-cache-semantics", "lru", "sha2", "base64"]
|
cache = ["http-cache-semantics", "lru", "sha2", "base64"]
|
||||||
sticky-cookie = ["base64", "sha2", "chrono"]
|
sticky-cookie = ["base64", "sha2", "chrono"]
|
||||||
native-tls-backend = ["hyper-tls"]
|
native-tls-backend = ["hyper-tls"]
|
||||||
rustls-backend = [] # not implemented yet
|
rustls-backend = ["hyper-rustls"]
|
||||||
native-roots = [] #"hyper-rustls/native-tokio"] # not implemented yet
|
rustls-backend-webpki = ["rustls-backend", "hyper-rustls/webpki-tokio"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
|
@ -52,28 +52,21 @@ thiserror = "1.0.56"
|
||||||
http = "1.0.0"
|
http = "1.0.0"
|
||||||
http-body-util = "0.1.0"
|
http-body-util = "0.1.0"
|
||||||
hyper = { version = "1.1.0", default-features = false }
|
hyper = { version = "1.1.0", default-features = false }
|
||||||
# hyper-util = { version = "0.1.2", features = ["full"] }
|
hyper-util = { version = "0.1.2", features = ["full"] }
|
||||||
hyper-util = { git = "https://github.com/junkurihara/hyper-util", features = [
|
|
||||||
"full",
|
|
||||||
], rev = "784109db021d076b0822ea5344a315e530831973" }
|
|
||||||
futures-util = { version = "0.3.30", default-features = false }
|
futures-util = { version = "0.3.30", default-features = false }
|
||||||
futures-channel = { version = "0.3.30", default-features = false }
|
futures-channel = { version = "0.3.30", default-features = false }
|
||||||
|
|
||||||
# http client for upstream
|
# http client for upstream
|
||||||
hyper-tls = { git = "https://github.com/junkurihara/hyper-tls", features = [
|
hyper-tls = { version = "0.6.0", features = [
|
||||||
"alpn",
|
"alpn",
|
||||||
"vendored",
|
"vendored",
|
||||||
], rev = "33dafc7251866260b66b0fc93c09f04f1923827f", optional = true }
|
], optional = true }
|
||||||
# hyper-tls = { version = "0.6.0", features = [
|
hyper-rustls = { version = "0.26.0", default-features = false, features = [
|
||||||
# "alpn",
|
"ring",
|
||||||
# "vendored",
|
"native-tokio",
|
||||||
# ], optional = true }
|
"http1",
|
||||||
# hyper-rustls = { version = "0.24.2", default-features = false, features = [
|
"http2",
|
||||||
# "tokio-runtime",
|
], optional = true }
|
||||||
# "webpki-tokio",
|
|
||||||
# "http1",
|
|
||||||
# "http2",
|
|
||||||
# ] }
|
|
||||||
|
|
||||||
# tls and cert management for server
|
# tls and cert management for server
|
||||||
hot_reload = "0.1.4"
|
hot_reload = "0.1.4"
|
||||||
|
|
@ -109,7 +102,7 @@ chrono = { version = "0.4.31", default-features = false, features = [
|
||||||
"alloc",
|
"alloc",
|
||||||
"clock",
|
"clock",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
base64 = { version = "0.21.6", optional = true }
|
base64 = { version = "0.21.7", optional = true }
|
||||||
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
||||||
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 {
|
impl RpxyCache {
|
||||||
|
#[allow(unused)]
|
||||||
/// Generate cache storage
|
/// Generate cache storage
|
||||||
pub(crate) async fn new(globals: &Globals) -> Option<Self> {
|
pub(crate) async fn new(globals: &Globals) -> Option<Self> {
|
||||||
if !globals.proxy_config.cache_enabled {
|
if !globals.proxy_config.cache_enabled {
|
||||||
|
|
@ -254,6 +255,7 @@ struct FileStore {
|
||||||
inner: Arc<RwLock<FileStoreInner>>,
|
inner: Arc<RwLock<FileStoreInner>>,
|
||||||
}
|
}
|
||||||
impl FileStore {
|
impl FileStore {
|
||||||
|
#[allow(unused)]
|
||||||
/// Build manager
|
/// Build manager
|
||||||
async fn new(runtime_handle: &tokio::runtime::Handle) -> Self {
|
async fn new(runtime_handle: &tokio::runtime::Handle) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
@ -300,6 +302,7 @@ struct FileStoreInner {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileStoreInner {
|
impl FileStoreInner {
|
||||||
|
#[allow(unused)]
|
||||||
/// Build new cache file manager.
|
/// Build new cache file manager.
|
||||||
/// This first creates cache file dir if not exists, and cleans up the file inside the directory.
|
/// 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.
|
/// TODO: Persistent cache is really difficult. `sqlite` or something like that is needed.
|
||||||
|
|
@ -436,6 +439,7 @@ struct LruCacheManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LruCacheManager {
|
impl LruCacheManager {
|
||||||
|
#[allow(unused)]
|
||||||
/// Build LruCache
|
/// Build LruCache
|
||||||
fn new(cache_max_entry: usize) -> Self {
|
fn new(cache_max_entry: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
#[allow(unused)]
|
||||||
use crate::{
|
use crate::{
|
||||||
error::{RpxyError, RpxyResult},
|
error::{RpxyError, RpxyResult},
|
||||||
globals::Globals,
|
globals::Globals,
|
||||||
|
|
@ -192,7 +193,7 @@ where
|
||||||
|
|
||||||
#[cfg(feature = "rustls-backend")]
|
#[cfg(feature = "rustls-backend")]
|
||||||
/// Build forwarder with hyper-rustls (rustls)
|
/// Build forwarder with hyper-rustls (rustls)
|
||||||
impl<B1> Forwarder<HttpConnector, B1>
|
impl<B1> Forwarder<hyper_rustls::HttpsConnector<HttpConnector>, B1>
|
||||||
where
|
where
|
||||||
B1: Body + Send + Unpin + 'static,
|
B1: Body + Send + Unpin + 'static,
|
||||||
<B1 as Body>::Data: Send,
|
<B1 as Body>::Data: Send,
|
||||||
|
|
@ -200,26 +201,32 @@ where
|
||||||
{
|
{
|
||||||
/// Build forwarder
|
/// Build forwarder
|
||||||
pub async fn try_new(_globals: &Arc<Globals>) -> RpxyResult<Self> {
|
pub async fn try_new(_globals: &Arc<Globals>) -> RpxyResult<Self> {
|
||||||
todo!("Not implemented yet. Please use native-tls-backend feature for now.");
|
// build hyper client with rustls and webpki, only https is allowed
|
||||||
// #[cfg(feature = "native-roots")]
|
#[cfg(feature = "rustls-backend-webpki")]
|
||||||
// let builder = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots();
|
let builder = hyper_rustls::HttpsConnectorBuilder::new().with_webpki_roots();
|
||||||
// #[cfg(feature = "native-roots")]
|
#[cfg(feature = "rustls-backend-webpki")]
|
||||||
// let builder_h2 = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots();
|
let builder_h2 = hyper_rustls::HttpsConnectorBuilder::new().with_webpki_roots();
|
||||||
// #[cfg(feature = "native-roots")]
|
#[cfg(feature = "rustls-backend-webpki")]
|
||||||
// info!("Native cert store is used for the connection to backend applications");
|
info!("Mozilla WebPKI root certs with rustls is used for the connection to backend applications");
|
||||||
|
|
||||||
// #[cfg(not(feature = "native-roots"))]
|
#[cfg(not(feature = "rustls-backend-webpki"))]
|
||||||
// let builder = hyper_rustls::HttpsConnectorBuilder::new().with_webpki_roots();
|
let builder = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots()?;
|
||||||
// #[cfg(not(feature = "native-roots"))]
|
#[cfg(not(feature = "rustls-backend-webpki"))]
|
||||||
// let builder_h2 = hyper_rustls::HttpsConnectorBuilder::new().with_webpki_roots();
|
let builder_h2 = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots()?;
|
||||||
// #[cfg(not(feature = "native-roots"))]
|
#[cfg(not(feature = "rustls-backend-webpki"))]
|
||||||
// info!("Mozilla WebPKI root certs is used for the connection to backend applications");
|
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 = builder.https_or_http().enable_all_versions().build();
|
||||||
// let connector_h2 = builder_h2.https_or_http().enable_http2().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);
|
Ok(Self {
|
||||||
// let inner_h2 = Client::builder().http2_only(true).build::<_, Body>(connector_h2);
|
inner,
|
||||||
|
inner_h2,
|
||||||
|
#[cfg(feature = "cache")]
|
||||||
|
cache: RpxyCache::new(_globals).await,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue