refactor
This commit is contained in:
parent
f98432fc69
commit
a52f74c434
3 changed files with 20 additions and 11 deletions
|
|
@ -13,8 +13,22 @@ publish.workspace = true
|
||||||
# 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", "rustls-backend", "sticky-cookie", "acme", "post-quantum"]
|
default = [
|
||||||
# default = ["http3-s2n", "cache", "rustls-backend", "sticky-cookie", "acme", "post-quantum"]
|
"http3-quinn",
|
||||||
|
"cache",
|
||||||
|
"rustls-backend",
|
||||||
|
"sticky-cookie",
|
||||||
|
"acme",
|
||||||
|
"post-quantum",
|
||||||
|
]
|
||||||
|
# default = [
|
||||||
|
# "http3-s2n",
|
||||||
|
# "cache",
|
||||||
|
# "rustls-backend",
|
||||||
|
# "sticky-cookie",
|
||||||
|
# "acme",
|
||||||
|
# "post-quantum",
|
||||||
|
# ]
|
||||||
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"]
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use super::{
|
||||||
utils_request::InspectParseHost,
|
utils_request::InspectParseHost,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::BackendAppManager,
|
backend::{BackendAppManager, LoadBalanceContext},
|
||||||
error::*,
|
error::*,
|
||||||
forwarder::{ForwardRequest, Forwarder},
|
forwarder::{ForwardRequest, Forwarder},
|
||||||
globals::Globals,
|
globals::Globals,
|
||||||
|
|
@ -24,10 +24,7 @@ use tokio::io::copy_bidirectional;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
/// Context object to handle sticky cookies at HTTP message handler
|
/// Context object to handle sticky cookies at HTTP message handler
|
||||||
pub(super) struct HandlerContext {
|
pub(super) struct HandlerContext {
|
||||||
#[cfg(feature = "sticky-cookie")]
|
pub(super) context_lb: Option<LoadBalanceContext>,
|
||||||
pub(super) context_lb: Option<crate::backend::LoadBalanceContext>,
|
|
||||||
#[cfg(not(feature = "sticky-cookie"))]
|
|
||||||
pub(super) context_lb: Option<()>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Builder)]
|
#[derive(Clone, Builder)]
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
backend::{UpstreamCandidates, UpstreamOption},
|
backend::{UpstreamCandidates, UpstreamOption},
|
||||||
log::*,
|
log::*,
|
||||||
};
|
};
|
||||||
use anyhow::{Result, anyhow, ensure};
|
use anyhow::{Result, anyhow};
|
||||||
use bytes::BufMut;
|
use bytes::BufMut;
|
||||||
use http::{HeaderMap, HeaderName, HeaderValue, Uri, header};
|
use http::{HeaderMap, HeaderName, HeaderValue, Uri, header};
|
||||||
use std::{borrow::Cow, net::SocketAddr};
|
use std::{borrow::Cow, net::SocketAddr};
|
||||||
|
|
@ -22,8 +22,6 @@ pub(super) fn takeout_sticky_cookie_lb_context(
|
||||||
headers: &mut HeaderMap,
|
headers: &mut HeaderMap,
|
||||||
expected_cookie_name: &str,
|
expected_cookie_name: &str,
|
||||||
) -> Result<Option<LoadBalanceContext>> {
|
) -> Result<Option<LoadBalanceContext>> {
|
||||||
use anyhow::ensure;
|
|
||||||
|
|
||||||
let mut headers_clone = headers.clone();
|
let mut headers_clone = headers.clone();
|
||||||
|
|
||||||
match headers_clone.entry(header::COOKIE) {
|
match headers_clone.entry(header::COOKIE) {
|
||||||
|
|
@ -37,7 +35,7 @@ pub(super) fn takeout_sticky_cookie_lb_context(
|
||||||
if sticky_cookies.is_empty() {
|
if sticky_cookies.is_empty() {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
ensure!(sticky_cookies.len() == 1, "Invalid cookie: Multiple sticky cookie values");
|
anyhow::ensure!(sticky_cookies.len() == 1, "Invalid cookie: Multiple sticky cookie values");
|
||||||
|
|
||||||
let cookies_passed_to_upstream = without_sticky_cookies.join("; ");
|
let cookies_passed_to_upstream = without_sticky_cookies.join("; ");
|
||||||
let cookie_passed_to_lb = sticky_cookies.first().unwrap();
|
let cookie_passed_to_lb = sticky_cookies.first().unwrap();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue