deps and refactor

This commit is contained in:
Jun Kurihara 2024-09-06 18:45:41 +09:00
commit 445d2162f5
No known key found for this signature in database
GPG key ID: D992B3E3DE1DED23
3 changed files with 8 additions and 17 deletions

View file

@ -64,9 +64,7 @@ hyper-tls = { version = "0.6.0", features = [
"alpn",
"vendored",
], optional = true }
# TODO: Work around to enable rustls-platform-verifier feature: https://github.com/rustls/hyper-rustls/pull/276
# hyper-rustls = { version = "0.27.2", default-features = false, features = [
hyper-rustls = { git = "https://github.com/junkurihara/hyper-rustls", branch = "main", features = [
hyper-rustls = { version = "0.27.3", default-features = false, features = [
"aws-lc-rs",
"http1",
"http2",

View file

@ -30,16 +30,12 @@ pub(super) fn takeout_sticky_cookie_lb_context(
let cookies_iter = entry
.iter()
.flat_map(|v| v.to_str().unwrap_or("").split(';').map(|v| v.trim()));
let (sticky_cookies, without_sticky_cookies): (Vec<_>, Vec<_>) = cookies_iter
.into_iter()
.partition(|v| v.starts_with(expected_cookie_name));
let (sticky_cookies, without_sticky_cookies): (Vec<_>, Vec<_>) =
cookies_iter.into_iter().partition(|v| v.starts_with(expected_cookie_name));
if sticky_cookies.is_empty() {
return Ok(None);
}
ensure!(
sticky_cookies.len() == 1,
"Invalid cookie: Multiple sticky cookie values"
);
ensure!(sticky_cookies.len() == 1, "Invalid cookie: Multiple sticky cookie values");
let cookies_passed_to_upstream = without_sticky_cookies.join("; ");
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 response header could be in multiple lines.
/// https://developer.mozilla.org/ja/docs/Web/HTTP/Headers/Set-Cookie
pub(super) fn set_sticky_cookie_lb_context(
headers: &mut HeaderMap,
context_from_lb: &LoadBalanceContext,
) -> Result<()> {
pub(super) fn set_sticky_cookie_lb_context(headers: &mut HeaderMap, context_from_lb: &LoadBalanceContext) -> Result<()> {
let sticky_cookie_string: String = context_from_lb.sticky_cookie.clone().try_into()?;
let new_header_val: HeaderValue = sticky_cookie_string.parse()?;
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
headers
.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>()?);
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(&[b',', b' ']);
new_value.put_slice(b", ");
new_value.put_slice(value.as_bytes());
entry.insert(HeaderValue::from_bytes(&new_value)?);
}

View file

@ -16,7 +16,7 @@ impl<B> InspectParseHost for Request<B> {
/// Inspect and extract hostname from either the request HOST header or request line
fn inspect_parse_host(&self) -> Result<Vec<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.
let mut iter = v.split(|ptr| ptr == &b'[' || ptr == &b']');
iter.next().ok_or(anyhow!("Invalid Host header"))?; // first item is always blank