Merge pull request #293 from junkurihara/tmp/sticky-cookie
sticky cookie
This commit is contained in:
commit
93668168bd
5 changed files with 22 additions and 12 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", "acme", "post-quantum"]
|
default = [
|
||||||
# default = ["http3-s2n", "cache", "rustls-backend", "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"]
|
||||||
|
|
@ -23,11 +37,10 @@ webpki-roots = ["rpxy-lib/webpki-roots"]
|
||||||
cache = ["rpxy-lib/cache"]
|
cache = ["rpxy-lib/cache"]
|
||||||
acme = ["rpxy-lib/acme", "rpxy-acme"]
|
acme = ["rpxy-lib/acme", "rpxy-acme"]
|
||||||
post-quantum = ["rpxy-lib/post-quantum"]
|
post-quantum = ["rpxy-lib/post-quantum"]
|
||||||
|
sticky-cookie = ["rpxy-lib/sticky-cookie"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rpxy-lib = { path = "../rpxy-lib/", default-features = false, features = [
|
rpxy-lib = { path = "../rpxy-lib/", default-features = false }
|
||||||
"sticky-cookie",
|
|
||||||
] }
|
|
||||||
|
|
||||||
# TODO: pin mimalloc due to compilation failure by musl
|
# TODO: pin mimalloc due to compilation failure by musl
|
||||||
mimalloc = { version = "=0.1.44", default-features = false }
|
mimalloc = { version = "=0.1.44", default-features = false }
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,4 @@ impl LoadBalance {
|
||||||
pub struct LoadBalanceContext {
|
pub struct LoadBalanceContext {
|
||||||
#[cfg(feature = "sticky-cookie")]
|
#[cfg(feature = "sticky-cookie")]
|
||||||
pub sticky_cookie: StickyCookie,
|
pub sticky_cookie: StickyCookie,
|
||||||
#[cfg(not(feature = "sticky-cookie"))]
|
|
||||||
pub sticky_cookie: (),
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ mod load_balance_sticky;
|
||||||
#[cfg(feature = "sticky-cookie")]
|
#[cfg(feature = "sticky-cookie")]
|
||||||
mod sticky_cookie;
|
mod sticky_cookie;
|
||||||
|
|
||||||
|
#[cfg(feature = "sticky-cookie")]
|
||||||
use super::upstream::Upstream;
|
use super::upstream::Upstream;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
|
@ -16,6 +17,7 @@ pub use load_balance_sticky::LoadBalanceStickyBuilder;
|
||||||
pub use sticky_cookie::{StickyCookie, StickyCookieValue};
|
pub use sticky_cookie::{StickyCookie, StickyCookieValue};
|
||||||
|
|
||||||
/// Result type for load balancing
|
/// Result type for load balancing
|
||||||
|
#[cfg(feature = "sticky-cookie")]
|
||||||
type LoadBalanceResult<T> = std::result::Result<T, LoadBalanceError>;
|
type LoadBalanceResult<T> = std::result::Result<T, LoadBalanceError>;
|
||||||
/// Describes things that can go wrong in the Load Balance
|
/// Describes things that can go wrong in the Load Balance
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
|
|
|
||||||
|
|
@ -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<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};
|
||||||
|
|
@ -35,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