deps and refactor
This commit is contained in:
parent
b427ba4bd7
commit
445d2162f5
3 changed files with 8 additions and 17 deletions
|
|
@ -64,9 +64,7 @@ hyper-tls = { version = "0.6.0", features = [
|
||||||
"alpn",
|
"alpn",
|
||||||
"vendored",
|
"vendored",
|
||||||
], optional = true }
|
], optional = true }
|
||||||
# TODO: Work around to enable rustls-platform-verifier feature: https://github.com/rustls/hyper-rustls/pull/276
|
hyper-rustls = { version = "0.27.3", default-features = false, features = [
|
||||||
# hyper-rustls = { version = "0.27.2", default-features = false, features = [
|
|
||||||
hyper-rustls = { git = "https://github.com/junkurihara/hyper-rustls", branch = "main", features = [
|
|
||||||
"aws-lc-rs",
|
"aws-lc-rs",
|
||||||
"http1",
|
"http1",
|
||||||
"http2",
|
"http2",
|
||||||
|
|
|
||||||
|
|
@ -30,16 +30,12 @@ pub(super) fn takeout_sticky_cookie_lb_context(
|
||||||
let cookies_iter = entry
|
let cookies_iter = entry
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|v| v.to_str().unwrap_or("").split(';').map(|v| v.trim()));
|
.flat_map(|v| v.to_str().unwrap_or("").split(';').map(|v| v.trim()));
|
||||||
let (sticky_cookies, without_sticky_cookies): (Vec<_>, Vec<_>) = cookies_iter
|
let (sticky_cookies, without_sticky_cookies): (Vec<_>, Vec<_>) =
|
||||||
.into_iter()
|
cookies_iter.into_iter().partition(|v| v.starts_with(expected_cookie_name));
|
||||||
.partition(|v| v.starts_with(expected_cookie_name));
|
|
||||||
if sticky_cookies.is_empty() {
|
if sticky_cookies.is_empty() {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
ensure!(
|
ensure!(sticky_cookies.len() == 1, "Invalid cookie: Multiple sticky cookie values");
|
||||||
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();
|
||||||
|
|
@ -59,10 +55,7 @@ pub(super) fn takeout_sticky_cookie_lb_context(
|
||||||
/// Set-Cookie if LB Sticky is enabled and if cookie is newly created/updated.
|
/// Set-Cookie if LB Sticky is enabled and if cookie is newly created/updated.
|
||||||
/// Set-Cookie response header could be in multiple lines.
|
/// Set-Cookie response header could be in multiple lines.
|
||||||
/// https://developer.mozilla.org/ja/docs/Web/HTTP/Headers/Set-Cookie
|
/// https://developer.mozilla.org/ja/docs/Web/HTTP/Headers/Set-Cookie
|
||||||
pub(super) fn set_sticky_cookie_lb_context(
|
pub(super) fn set_sticky_cookie_lb_context(headers: &mut HeaderMap, context_from_lb: &LoadBalanceContext) -> Result<()> {
|
||||||
headers: &mut HeaderMap,
|
|
||||||
context_from_lb: &LoadBalanceContext,
|
|
||||||
) -> Result<()> {
|
|
||||||
let sticky_cookie_string: String = context_from_lb.sticky_cookie.clone().try_into()?;
|
let sticky_cookie_string: String = context_from_lb.sticky_cookie.clone().try_into()?;
|
||||||
let new_header_val: HeaderValue = sticky_cookie_string.parse()?;
|
let new_header_val: HeaderValue = sticky_cookie_string.parse()?;
|
||||||
let expected_cookie_name = &context_from_lb.sticky_cookie.value.name;
|
let expected_cookie_name = &context_from_lb.sticky_cookie.value.name;
|
||||||
|
|
@ -122,7 +115,7 @@ pub(super) fn apply_upstream_options_to_header(
|
||||||
// add upgrade-insecure-requests in request header if not exist
|
// add upgrade-insecure-requests in request header if not exist
|
||||||
headers
|
headers
|
||||||
.entry(header::UPGRADE_INSECURE_REQUESTS)
|
.entry(header::UPGRADE_INSECURE_REQUESTS)
|
||||||
.or_insert(HeaderValue::from_bytes(&[b'1']).unwrap());
|
.or_insert(HeaderValue::from_bytes(b"1").unwrap());
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
@ -141,7 +134,7 @@ pub(super) fn append_header_entry_with_comma(headers: &mut HeaderMap, key: &str,
|
||||||
// entry.append(value.parse::<HeaderValue>()?);
|
// entry.append(value.parse::<HeaderValue>()?);
|
||||||
let mut new_value = Vec::<u8>::with_capacity(entry.get().as_bytes().len() + 2 + value.len());
|
let mut new_value = Vec::<u8>::with_capacity(entry.get().as_bytes().len() + 2 + value.len());
|
||||||
new_value.put_slice(entry.get().as_bytes());
|
new_value.put_slice(entry.get().as_bytes());
|
||||||
new_value.put_slice(&[b',', b' ']);
|
new_value.put_slice(b", ");
|
||||||
new_value.put_slice(value.as_bytes());
|
new_value.put_slice(value.as_bytes());
|
||||||
entry.insert(HeaderValue::from_bytes(&new_value)?);
|
entry.insert(HeaderValue::from_bytes(&new_value)?);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ impl<B> InspectParseHost for Request<B> {
|
||||||
/// Inspect and extract hostname from either the request HOST header or request line
|
/// Inspect and extract hostname from either the request HOST header or request line
|
||||||
fn inspect_parse_host(&self) -> Result<Vec<u8>> {
|
fn inspect_parse_host(&self) -> Result<Vec<u8>> {
|
||||||
let drop_port = |v: &[u8]| {
|
let drop_port = |v: &[u8]| {
|
||||||
if v.starts_with(&[b'[']) {
|
if v.starts_with(b"[") {
|
||||||
// v6 address with bracket case. if port is specified, always it is in this case.
|
// v6 address with bracket case. if port is specified, always it is in this case.
|
||||||
let mut iter = v.split(|ptr| ptr == &b'[' || ptr == &b']');
|
let mut iter = v.split(|ptr| ptr == &b'[' || ptr == &b']');
|
||||||
iter.next().ok_or(anyhow!("Invalid Host header"))?; // first item is always blank
|
iter.next().ok_or(anyhow!("Invalid Host header"))?; // first item is always blank
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue