rfc6265 oneliner cookie

This commit is contained in:
Jun Kurihara 2022-08-13 04:27:00 +09:00
commit c9949ff594
No known key found for this signature in database
GPG key ID: 48ADFD173ED22B03

View file

@ -95,6 +95,22 @@ pub(super) fn add_header_entry_overwrite_if_exist(
Ok(())
}
pub(super) fn make_cookie_single_line(headers: &mut HeaderMap) -> Result<()> {
// Sometimes violates RFC6265: https://www.rfc-editor.org/rfc/rfc6265#section-5.4
// https://stackoverflow.com/questions/4843556/in-http-specification-what-is-the-string-that-separates-cookies
let cookies = headers
.iter()
.filter(|(k, _)| **k == hyper::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())?);
}
Ok(())
}
pub(super) fn add_forwarding_header(
headers: &mut HeaderMap,
client_addr: &SocketAddr,
@ -107,6 +123,8 @@ pub(super) fn add_forwarding_header(
let canonical_client_addr = client_addr.to_canonical().ip().to_string();
append_header_entry_with_comma(headers, "x-forwarded-for", &canonical_client_addr)?;
make_cookie_single_line(headers)?;
/////////// As Nginx
// If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
// scheme used to connect to this server