refactor
This commit is contained in:
parent
f2c6d738b6
commit
265cc025b0
2 changed files with 13 additions and 12 deletions
|
|
@ -23,7 +23,7 @@ pub(super) fn takeout_sticky_cookie_lb_context(
|
|||
) -> Result<Option<LbContext>> {
|
||||
let mut headers_clone = headers.clone();
|
||||
|
||||
match headers_clone.entry(hyper::header::COOKIE) {
|
||||
match headers_clone.entry(header::COOKIE) {
|
||||
header::Entry::Vacant(_) => Ok(None),
|
||||
header::Entry::Occupied(entry) => {
|
||||
let cookies_iter = entry
|
||||
|
|
@ -43,8 +43,8 @@ pub(super) fn takeout_sticky_cookie_lb_context(
|
|||
}
|
||||
let cookies_passed_to_upstream = without_sticky_cookies.join("; ");
|
||||
let cookie_passed_to_lb = sticky_cookies.first().unwrap();
|
||||
headers.remove(hyper::header::COOKIE);
|
||||
headers.insert(hyper::header::COOKIE, cookies_passed_to_upstream.parse()?);
|
||||
headers.remove(header::COOKIE);
|
||||
headers.insert(header::COOKIE, cookies_passed_to_upstream.parse()?);
|
||||
|
||||
let sticky_cookie = StickyCookie {
|
||||
value: StickyCookieValue::try_from(cookie_passed_to_lb, expected_cookie_name)?,
|
||||
|
|
@ -63,7 +63,7 @@ pub(super) fn set_sticky_cookie_lb_context(headers: &mut HeaderMap, context_from
|
|||
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;
|
||||
match headers.entry(hyper::header::SET_COOKIE) {
|
||||
match headers.entry(header::SET_COOKIE) {
|
||||
header::Entry::Vacant(entry) => {
|
||||
entry.insert(new_header_val);
|
||||
}
|
||||
|
|
@ -173,13 +173,13 @@ pub(super) fn add_header_entry_overwrite_if_exist(
|
|||
pub(super) fn make_cookie_single_line(headers: &mut HeaderMap) -> Result<()> {
|
||||
let cookies = headers
|
||||
.iter()
|
||||
.filter(|(k, _)| **k == hyper::header::COOKIE)
|
||||
.filter(|(k, _)| **k == header::COOKIE)
|
||||
.map(|(_, v)| v.to_str().unwrap_or(""))
|
||||
.collect::<Vec<_>>()
|
||||
.join("; ");
|
||||
if !cookies.is_empty() {
|
||||
headers.remove(hyper::header::COOKIE);
|
||||
headers.insert(hyper::header::COOKIE, HeaderValue::from_bytes(cookies.as_bytes())?);
|
||||
headers.remove(header::COOKIE);
|
||||
headers.insert(header::COOKIE, HeaderValue::from_bytes(cookies.as_bytes())?);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use crate::utils::ToCanonical;
|
||||
use hyper::header;
|
||||
use std::net::SocketAddr;
|
||||
pub use tracing::{debug, error, info, warn};
|
||||
|
||||
|
|
@ -20,7 +21,7 @@ pub struct MessageLog {
|
|||
|
||||
impl<T> From<&hyper::Request<T>> for MessageLog {
|
||||
fn from(req: &hyper::Request<T>) -> Self {
|
||||
let header_mapper = |v: hyper::header::HeaderName| {
|
||||
let header_mapper = |v: header::HeaderName| {
|
||||
req
|
||||
.headers()
|
||||
.get(v)
|
||||
|
|
@ -31,7 +32,7 @@ impl<T> From<&hyper::Request<T>> for MessageLog {
|
|||
// tls_server_name: "".to_string(),
|
||||
client_addr: "".to_string(),
|
||||
method: req.method().to_string(),
|
||||
host: header_mapper(hyper::header::HOST),
|
||||
host: header_mapper(header::HOST),
|
||||
p_and_q: req
|
||||
.uri()
|
||||
.path_and_query()
|
||||
|
|
@ -40,8 +41,8 @@ impl<T> From<&hyper::Request<T>> for MessageLog {
|
|||
version: req.version(),
|
||||
uri_scheme: req.uri().scheme_str().unwrap_or("").to_string(),
|
||||
uri_host: req.uri().host().unwrap_or("").to_string(),
|
||||
ua: header_mapper(hyper::header::USER_AGENT),
|
||||
xff: header_mapper(hyper::header::HeaderName::from_static("x-forwarded-for")),
|
||||
ua: header_mapper(header::USER_AGENT),
|
||||
xff: header_mapper(header::HeaderName::from_static("x-forwarded-for")),
|
||||
status: "".to_string(),
|
||||
upstream: "".to_string(),
|
||||
}
|
||||
|
|
@ -61,7 +62,7 @@ impl MessageLog {
|
|||
self.status = status_code.to_string();
|
||||
self
|
||||
}
|
||||
pub fn xff(&mut self, xff: &Option<&hyper::header::HeaderValue>) -> &mut Self {
|
||||
pub fn xff(&mut self, xff: &Option<&header::HeaderValue>) -> &mut Self {
|
||||
self.xff = xff.map_or_else(|| "", |v| v.to_str().unwrap_or("")).to_string();
|
||||
self
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue