mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-11 07:36:53 +00:00
chore: upgrade dependencies and migrate to aws-lc-rs (#1333)
This commit is contained in:
+51
-52
@@ -56,36 +56,36 @@ fn is_xff_header_enabled() -> bool {
|
||||
///
|
||||
pub fn get_source_scheme(headers: &HeaderMap) -> Option<String> {
|
||||
// Retrieve the scheme from X-Forwarded-Proto.
|
||||
if let Some(proto) = headers.get(X_FORWARDED_PROTO) {
|
||||
if let Ok(proto_str) = proto.to_str() {
|
||||
return Some(proto_str.to_lowercase());
|
||||
}
|
||||
if let Some(proto) = headers.get(X_FORWARDED_PROTO)
|
||||
&& let Ok(proto_str) = proto.to_str()
|
||||
{
|
||||
return Some(proto_str.to_lowercase());
|
||||
}
|
||||
|
||||
if let Some(proto) = headers.get(X_FORWARDED_SCHEME) {
|
||||
if let Ok(proto_str) = proto.to_str() {
|
||||
return Some(proto_str.to_lowercase());
|
||||
}
|
||||
if let Some(proto) = headers.get(X_FORWARDED_SCHEME)
|
||||
&& let Ok(proto_str) = proto.to_str()
|
||||
{
|
||||
return Some(proto_str.to_lowercase());
|
||||
}
|
||||
|
||||
if let Some(forwarded) = headers.get(FORWARDED) {
|
||||
if let Ok(forwarded_str) = forwarded.to_str() {
|
||||
// match should contain at least two elements if the protocol was
|
||||
// specified in the Forwarded header. The first element will always be
|
||||
// the 'for=', which we ignore, subsequently we proceed to look for
|
||||
// 'proto=' which should precede right after `for=` if not
|
||||
// we simply ignore the values and return empty. This is in line
|
||||
// with the approach we took for returning first ip from multiple
|
||||
// params.
|
||||
if let Some(for_match) = FOR_REGEX.captures(forwarded_str) {
|
||||
if for_match.len() > 1 {
|
||||
let remaining = &for_match[2];
|
||||
if let Some(proto_match) = PROTO_REGEX.captures(remaining) {
|
||||
if proto_match.len() > 1 {
|
||||
return Some(proto_match[2].to_lowercase());
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(forwarded) = headers.get(FORWARDED)
|
||||
&& let Ok(forwarded_str) = forwarded.to_str()
|
||||
{
|
||||
// match should contain at least two elements if the protocol was
|
||||
// specified in the Forwarded header. The first element will always be
|
||||
// the 'for=', which we ignore, subsequently we proceed to look for
|
||||
// 'proto=' which should precede right after `for=` if not
|
||||
// we simply ignore the values and return empty. This is in line
|
||||
// with the approach we took for returning first ip from multiple
|
||||
// params.
|
||||
if let Some(for_match) = FOR_REGEX.captures(forwarded_str)
|
||||
&& for_match.len() > 1
|
||||
{
|
||||
let remaining = &for_match[2];
|
||||
if let Some(proto_match) = PROTO_REGEX.captures(remaining)
|
||||
&& proto_match.len() > 1
|
||||
{
|
||||
return Some(proto_match[2].to_lowercase());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,17 +105,16 @@ pub fn get_source_scheme(headers: &HeaderMap) -> Option<String> {
|
||||
pub fn get_source_ip_from_headers(headers: &HeaderMap) -> Option<String> {
|
||||
let mut addr = None;
|
||||
|
||||
if is_xff_header_enabled() {
|
||||
if let Some(forwarded_for) = headers.get(X_FORWARDED_FOR) {
|
||||
if let Ok(forwarded_str) = forwarded_for.to_str() {
|
||||
// Only grab the first (client) address. Note that '192.168.0.1,
|
||||
// 10.1.1.1' is a valid key for X-Forwarded-For where addresses after
|
||||
// the first may represent forwarding proxies earlier in the chain.
|
||||
let first_comma = forwarded_str.find(", ");
|
||||
let end = first_comma.unwrap_or(forwarded_str.len());
|
||||
addr = Some(forwarded_str[..end].to_string());
|
||||
}
|
||||
}
|
||||
if is_xff_header_enabled()
|
||||
&& let Some(forwarded_for) = headers.get(X_FORWARDED_FOR)
|
||||
&& let Ok(forwarded_str) = forwarded_for.to_str()
|
||||
{
|
||||
// Only grab the first (client) address. Note that '192.168.0.1,
|
||||
// 10.1.1.1' is a valid key for X-Forwarded-For where addresses after
|
||||
// the first may represent forwarding proxies earlier in the chain.
|
||||
let first_comma = forwarded_str.find(", ");
|
||||
let end = first_comma.unwrap_or(forwarded_str.len());
|
||||
addr = Some(forwarded_str[..end].to_string());
|
||||
}
|
||||
|
||||
if addr.is_none() {
|
||||
@@ -125,21 +124,21 @@ pub fn get_source_ip_from_headers(headers: &HeaderMap) -> Option<String> {
|
||||
// request).
|
||||
addr = Some(real_ip_str.to_string());
|
||||
}
|
||||
} else if let Some(forwarded) = headers.get(FORWARDED) {
|
||||
if let Ok(forwarded_str) = forwarded.to_str() {
|
||||
// match should contain at least two elements if the protocol was
|
||||
// specified in the Forwarded header. The first element will always be
|
||||
// the 'for=' capture, which we ignore. In the case of multiple IP
|
||||
// addresses (for=8.8.8.8, 8.8.4.4, 172.16.1.20 is valid) we only
|
||||
// extract the first, which should be the client IP.
|
||||
if let Some(for_match) = FOR_REGEX.captures(forwarded_str) {
|
||||
if for_match.len() > 1 {
|
||||
// IPv6 addresses in Forwarded headers are quoted-strings. We strip
|
||||
// these quotes.
|
||||
let ip = for_match[1].trim_matches('"');
|
||||
addr = Some(ip.to_string());
|
||||
}
|
||||
}
|
||||
} else if let Some(forwarded) = headers.get(FORWARDED)
|
||||
&& let Ok(forwarded_str) = forwarded.to_str()
|
||||
{
|
||||
// match should contain at least two elements if the protocol was
|
||||
// specified in the Forwarded header. The first element will always be
|
||||
// the 'for=' capture, which we ignore. In the case of multiple IP
|
||||
// addresses (for=8.8.8.8, 8.8.4.4, 172.16.1.20 is valid) we only
|
||||
// extract the first, which should be the client IP.
|
||||
if let Some(for_match) = FOR_REGEX.captures(forwarded_str)
|
||||
&& for_match.len() > 1
|
||||
{
|
||||
// IPv6 addresses in Forwarded headers are quoted-strings. We strip
|
||||
// these quotes.
|
||||
let ip = for_match[1].trim_matches('"');
|
||||
addr = Some(ip.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user