preparing nightly-build
This commit is contained in:
parent
92638ccd2a
commit
f41a2213f9
13 changed files with 109 additions and 110 deletions
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "rpxy-lib"
|
||||
version = "0.7.0"
|
||||
version = "0.7.0-alpha.0"
|
||||
authors = ["Jun Kurihara"]
|
||||
homepage = "https://github.com/junkurihara/rust-rpxy"
|
||||
repository = "https://github.com/junkurihara/rust-rpxy"
|
||||
|
|
@ -21,11 +21,11 @@ http3-s2n = [
|
|||
"s2n-quic-rustls",
|
||||
"s2n-quic-h3",
|
||||
]
|
||||
cache = ["http-cache-semantics", "lru", "sha2", "base64"]
|
||||
sticky-cookie = ["base64", "sha2", "chrono"]
|
||||
native-tls-backend = ["hyper-tls"]
|
||||
rustls-backend = []
|
||||
cache = ["http-cache-semantics", "lru", "sha2", "base64"]
|
||||
native-roots = [] #"hyper-rustls/native-tokio"]
|
||||
rustls-backend = [] # not implemented yet
|
||||
native-roots = [] #"hyper-rustls/native-tokio"] # not implemented yet
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.5"
|
||||
|
|
@ -33,7 +33,7 @@ rustc-hash = "1.1.0"
|
|||
bytes = "1.5.0"
|
||||
derive_builder = "0.12.0"
|
||||
futures = { version = "0.3.29", features = ["alloc", "async-await"] }
|
||||
tokio = { version = "1.34.0", default-features = false, features = [
|
||||
tokio = { version = "1.35.0", default-features = false, features = [
|
||||
"net",
|
||||
"rt-multi-thread",
|
||||
"time",
|
||||
|
|
@ -57,7 +57,10 @@ futures-util = { version = "0.3.29", default-features = false }
|
|||
futures-channel = { version = "0.3.29", default-features = false }
|
||||
|
||||
# http client for upstream
|
||||
hyper-tls = { version = "0.6.0", features = ["alpn"], optional = true }
|
||||
hyper-tls = { version = "0.6.0", features = [
|
||||
"alpn",
|
||||
"vendored",
|
||||
], optional = true }
|
||||
# hyper-rustls = { version = "0.24.2", default-features = false, features = [
|
||||
# "tokio-runtime",
|
||||
# "webpki-tokio",
|
||||
|
|
|
|||
5
rpxy-lib/src/forwarder/cache/cache_error.rs
vendored
5
rpxy-lib/src/forwarder/cache/cache_error.rs
vendored
|
|
@ -1,6 +1,6 @@
|
|||
use thiserror::Error;
|
||||
|
||||
pub type CacheResult<T> = std::result::Result<T, CacheError>;
|
||||
pub(crate) type CacheResult<T> = std::result::Result<T, CacheError>;
|
||||
|
||||
/// Describes things that can go wrong in the Rpxy
|
||||
#[derive(Debug, Error)]
|
||||
|
|
@ -9,9 +9,6 @@ pub enum CacheError {
|
|||
#[error("Invalid null request and/or response")]
|
||||
NullRequestOrResponse,
|
||||
|
||||
#[error("Failed to write byte buffer")]
|
||||
FailedToWriteByteBufferForCache,
|
||||
|
||||
#[error("Failed to acquire mutex lock for cache")]
|
||||
FailedToAcquiredMutexLockForCache,
|
||||
|
||||
|
|
|
|||
20
rpxy-lib/src/forwarder/cache/cache_main.rs
vendored
20
rpxy-lib/src/forwarder/cache/cache_main.rs
vendored
|
|
@ -30,7 +30,7 @@ use tokio::{
|
|||
/* ---------------------------------------------- */
|
||||
#[derive(Clone, Debug)]
|
||||
/// Cache main manager
|
||||
pub struct RpxyCache {
|
||||
pub(crate) struct RpxyCache {
|
||||
/// Inner lru cache manager storing http message caching policy
|
||||
inner: LruCacheManager,
|
||||
/// Managing cache file objects through RwLock's lock mechanism for file lock
|
||||
|
|
@ -47,7 +47,7 @@ pub struct RpxyCache {
|
|||
|
||||
impl RpxyCache {
|
||||
/// Generate cache storage
|
||||
pub async fn new(globals: &Globals) -> Option<Self> {
|
||||
pub(crate) async fn new(globals: &Globals) -> Option<Self> {
|
||||
if !globals.proxy_config.cache_enabled {
|
||||
return None;
|
||||
}
|
||||
|
|
@ -80,7 +80,7 @@ impl RpxyCache {
|
|||
}
|
||||
|
||||
/// Count cache entries
|
||||
pub async fn count(&self) -> (usize, usize, usize) {
|
||||
pub(crate) async fn count(&self) -> (usize, usize, usize) {
|
||||
let total = self.inner.count();
|
||||
let file = self.file_store.count().await;
|
||||
let on_memory = total - file;
|
||||
|
|
@ -88,7 +88,7 @@ impl RpxyCache {
|
|||
}
|
||||
|
||||
/// Put response into the cache
|
||||
pub async fn put(
|
||||
pub(crate) async fn put(
|
||||
&self,
|
||||
uri: &hyper::Uri,
|
||||
mut body: Incoming,
|
||||
|
|
@ -186,7 +186,7 @@ impl RpxyCache {
|
|||
}
|
||||
|
||||
/// Get cached response
|
||||
pub async fn get<R>(&self, req: &Request<R>) -> Option<Response<ResponseBody>> {
|
||||
pub(crate) async fn get<R>(&self, req: &Request<R>) -> Option<Response<ResponseBody>> {
|
||||
debug!(
|
||||
"Current cache status: (total, on-memory, file) = {:?}",
|
||||
self.count().await
|
||||
|
|
@ -394,7 +394,7 @@ impl FileStoreInner {
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
/// Cache target in hybrid manner of on-memory and file system
|
||||
pub enum CacheFileOrOnMemory {
|
||||
pub(crate) enum CacheFileOrOnMemory {
|
||||
/// Pointer to the temporary cache file
|
||||
File(PathBuf),
|
||||
/// Cached body itself
|
||||
|
|
@ -418,11 +418,11 @@ impl CacheFileOrOnMemory {
|
|||
/// Cache object definition
|
||||
struct CacheObject {
|
||||
/// Cache policy to determine if the stored cache can be used as a response to a new incoming request
|
||||
pub policy: CachePolicy,
|
||||
policy: CachePolicy,
|
||||
/// Cache target: on-memory object or temporary file
|
||||
pub target: CacheFileOrOnMemory,
|
||||
target: CacheFileOrOnMemory,
|
||||
/// SHA256 hash of target to strongly bind the cache metadata (this object) and file target
|
||||
pub hash: Bytes,
|
||||
hash: Bytes,
|
||||
}
|
||||
|
||||
/* ---------------------------------------------- */
|
||||
|
|
@ -490,7 +490,7 @@ impl LruCacheManager {
|
|||
|
||||
/* ---------------------------------------------- */
|
||||
/// Generate cache policy if the response is cacheable
|
||||
pub fn get_policy_if_cacheable<B1, B2>(
|
||||
pub(crate) fn get_policy_if_cacheable<B1, B2>(
|
||||
req: Option<&Request<B1>>,
|
||||
res: Option<&Response<B2>>,
|
||||
) -> CacheResult<Option<CachePolicy>>
|
||||
|
|
|
|||
2
rpxy-lib/src/forwarder/cache/mod.rs
vendored
2
rpxy-lib/src/forwarder/cache/mod.rs
vendored
|
|
@ -2,4 +2,4 @@ mod cache_error;
|
|||
mod cache_main;
|
||||
|
||||
pub use cache_error::CacheError;
|
||||
pub use cache_main::{get_policy_if_cacheable, CacheFileOrOnMemory, RpxyCache};
|
||||
pub(crate) use cache_main::{get_policy_if_cacheable, RpxyCache};
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ where
|
|||
<B as Body>::Error: Into<Box<(dyn std::error::Error + Send + Sync + 'static)>>,
|
||||
{
|
||||
/// Build inner client with http
|
||||
pub fn try_new(_globals: &Arc<Globals>) -> RpxyResult<Self> {
|
||||
pub async fn try_new(_globals: &Arc<Globals>) -> RpxyResult<Self> {
|
||||
warn!(
|
||||
"
|
||||
--------------------------------------------------------------------------------------------------
|
||||
|
|
@ -134,6 +134,7 @@ Please enable native-tls-backend or rustls-backend feature to enable TLS support
|
|||
let mut http = HttpConnector::new();
|
||||
http.set_reuse_address(true);
|
||||
let inner = Client::builder(executor).build::<_, B>(http);
|
||||
let inner_h2 = inner.clone();
|
||||
|
||||
Ok(Self {
|
||||
inner,
|
||||
|
|
@ -191,7 +192,7 @@ where
|
|||
|
||||
#[cfg(feature = "rustls-backend")]
|
||||
/// Build forwarder with hyper-rustls (rustls)
|
||||
impl<B1> Forwarder<hyper_tls::HttpsConnector<HttpConnector>, B1>
|
||||
impl<B1> Forwarder<HttpConnector, B1>
|
||||
where
|
||||
B1: Body + Send + Unpin + 'static,
|
||||
<B1 as Body>::Data: Send,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
use super::body::IncomingLike;
|
||||
use crate::error::RpxyError;
|
||||
use http_body_util::{combinators, BodyExt, Empty, Full};
|
||||
use hyper::body::{Body, Bytes, Incoming};
|
||||
use futures::channel::mpsc::UnboundedReceiver;
|
||||
use http_body_util::{combinators, BodyExt, Empty, Full, StreamBody};
|
||||
use hyper::body::{Body, Bytes, Frame, Incoming};
|
||||
use std::pin::Pin;
|
||||
|
||||
/// Type for synthetic boxed body
|
||||
pub(crate) type BoxBody = combinators::BoxBody<Bytes, hyper::Error>;
|
||||
pub type BoxBody = combinators::BoxBody<Bytes, hyper::Error>;
|
||||
|
||||
/// helper function to build a empty body
|
||||
pub(crate) fn empty() -> BoxBody {
|
||||
|
|
@ -17,11 +18,12 @@ pub(crate) fn full(body: Bytes) -> BoxBody {
|
|||
Full::new(body).map_err(|never| match never {}).boxed()
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
/* ------------------------------------ */
|
||||
/// Request body used in this project
|
||||
/// - Incoming: just a type that only forwards the downstream request body to upstream.
|
||||
/// - IncomingLike: a Incoming-like type in which channel is used
|
||||
pub(crate) enum RequestBody {
|
||||
pub enum RequestBody {
|
||||
Incoming(Incoming),
|
||||
IncomingLike(IncomingLike),
|
||||
}
|
||||
|
|
@ -42,24 +44,16 @@ impl Body for RequestBody {
|
|||
}
|
||||
|
||||
/* ------------------------------------ */
|
||||
#[cfg(feature = "cache")]
|
||||
use futures::channel::mpsc::UnboundedReceiver;
|
||||
#[cfg(feature = "cache")]
|
||||
use http_body_util::StreamBody;
|
||||
#[cfg(feature = "cache")]
|
||||
use hyper::body::Frame;
|
||||
|
||||
#[cfg(feature = "cache")]
|
||||
pub(crate) type UnboundedStreamBody = StreamBody<UnboundedReceiver<Result<Frame<bytes::Bytes>, hyper::Error>>>;
|
||||
pub type UnboundedStreamBody = StreamBody<UnboundedReceiver<Result<Frame<bytes::Bytes>, hyper::Error>>>;
|
||||
|
||||
#[allow(unused)]
|
||||
/// Response body use in this project
|
||||
/// - Incoming: just a type that only forwards the upstream response body to downstream.
|
||||
/// - Boxed: a type that is generated from cache or synthetic response body, e.g.,, small byte object.
|
||||
/// - Streamed: another type that is generated from stream, e.g., large byte object.
|
||||
pub(crate) enum ResponseBody {
|
||||
pub enum ResponseBody {
|
||||
Incoming(Incoming),
|
||||
Boxed(BoxBody),
|
||||
#[cfg(feature = "cache")]
|
||||
Streamed(UnboundedStreamBody),
|
||||
}
|
||||
|
||||
|
|
@ -73,9 +67,7 @@ impl Body for ResponseBody {
|
|||
) -> std::task::Poll<Option<Result<Frame<Self::Data>, Self::Error>>> {
|
||||
match self.get_mut() {
|
||||
ResponseBody::Incoming(incoming) => Pin::new(incoming).poll_frame(cx),
|
||||
#[cfg(feature = "cache")]
|
||||
ResponseBody::Boxed(boxed) => Pin::new(boxed).poll_frame(cx),
|
||||
#[cfg(feature = "cache")]
|
||||
ResponseBody::Streamed(streamed) => Pin::new(streamed).poll_frame(cx),
|
||||
}
|
||||
.map_err(RpxyError::HyperBodyError)
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ where
|
|||
// Functions to generate messages
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
#[allow(unused_variables)]
|
||||
/// Manipulate a response message sent from a backend application to forward downstream to a client.
|
||||
pub(super) fn generate_response_forwarded<B>(
|
||||
&self,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
mod proxy_h3;
|
||||
mod proxy_main;
|
||||
mod socket;
|
||||
|
||||
#[cfg(any(feature = "http3-quinn", feature = "http3-s2n"))]
|
||||
mod proxy_h3;
|
||||
#[cfg(feature = "http3-quinn")]
|
||||
mod proxy_quic_quinn;
|
||||
#[cfg(all(feature = "http3-s2n", not(feature = "http3-quinn")))]
|
||||
mod proxy_quic_s2n;
|
||||
mod socket;
|
||||
|
||||
use crate::{
|
||||
globals::Globals,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue