mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-10 15:16:56 +00:00
@@ -224,12 +224,30 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_from_str() {
|
||||
assert_eq!(CompressionAlgorithm::from_str("gzip").expect("operation should succeed"), CompressionAlgorithm::Gzip);
|
||||
assert_eq!(CompressionAlgorithm::from_str("deflate").expect("operation should succeed"), CompressionAlgorithm::Deflate);
|
||||
assert_eq!(CompressionAlgorithm::from_str("zstd").expect("operation should succeed"), CompressionAlgorithm::Zstd);
|
||||
assert_eq!(CompressionAlgorithm::from_str("lz4").expect("operation should succeed"), CompressionAlgorithm::Lz4);
|
||||
assert_eq!(CompressionAlgorithm::from_str("brotli").expect("operation should succeed"), CompressionAlgorithm::Brotli);
|
||||
assert_eq!(CompressionAlgorithm::from_str("snappy").expect("operation should succeed"), CompressionAlgorithm::Snappy);
|
||||
assert_eq!(
|
||||
CompressionAlgorithm::from_str("gzip").expect("operation should succeed"),
|
||||
CompressionAlgorithm::Gzip
|
||||
);
|
||||
assert_eq!(
|
||||
CompressionAlgorithm::from_str("deflate").expect("operation should succeed"),
|
||||
CompressionAlgorithm::Deflate
|
||||
);
|
||||
assert_eq!(
|
||||
CompressionAlgorithm::from_str("zstd").expect("operation should succeed"),
|
||||
CompressionAlgorithm::Zstd
|
||||
);
|
||||
assert_eq!(
|
||||
CompressionAlgorithm::from_str("lz4").expect("operation should succeed"),
|
||||
CompressionAlgorithm::Lz4
|
||||
);
|
||||
assert_eq!(
|
||||
CompressionAlgorithm::from_str("brotli").expect("operation should succeed"),
|
||||
CompressionAlgorithm::Brotli
|
||||
);
|
||||
assert_eq!(
|
||||
CompressionAlgorithm::from_str("snappy").expect("operation should succeed"),
|
||||
CompressionAlgorithm::Snappy
|
||||
);
|
||||
assert!(CompressionAlgorithm::from_str("unknown").is_err());
|
||||
}
|
||||
|
||||
@@ -278,12 +296,27 @@ mod tests {
|
||||
println!("{name}: {size} bytes, {dur:?}");
|
||||
}
|
||||
// All should decompress to the original
|
||||
assert_eq!(decompress_block(&gzip, CompressionAlgorithm::Gzip).expect("operation should succeed"), data);
|
||||
assert_eq!(decompress_block(&deflate, CompressionAlgorithm::Deflate).expect("operation should succeed"), data);
|
||||
assert_eq!(decompress_block(&zstd, CompressionAlgorithm::Zstd).expect("operation should succeed"), data);
|
||||
assert_eq!(
|
||||
decompress_block(&gzip, CompressionAlgorithm::Gzip).expect("operation should succeed"),
|
||||
data
|
||||
);
|
||||
assert_eq!(
|
||||
decompress_block(&deflate, CompressionAlgorithm::Deflate).expect("operation should succeed"),
|
||||
data
|
||||
);
|
||||
assert_eq!(
|
||||
decompress_block(&zstd, CompressionAlgorithm::Zstd).expect("operation should succeed"),
|
||||
data
|
||||
);
|
||||
assert_eq!(decompress_block(&lz4, CompressionAlgorithm::Lz4).expect("operation should succeed"), data);
|
||||
assert_eq!(decompress_block(&brotli, CompressionAlgorithm::Brotli).expect("operation should succeed"), data);
|
||||
assert_eq!(decompress_block(&snappy, CompressionAlgorithm::Snappy).expect("operation should succeed"), data);
|
||||
assert_eq!(
|
||||
decompress_block(&brotli, CompressionAlgorithm::Brotli).expect("operation should succeed"),
|
||||
data
|
||||
);
|
||||
assert_eq!(
|
||||
decompress_block(&snappy, CompressionAlgorithm::Snappy).expect("operation should succeed"),
|
||||
data
|
||||
);
|
||||
// All compressed results should not be empty
|
||||
assert!(
|
||||
!gzip.is_empty()
|
||||
|
||||
@@ -30,8 +30,10 @@ pub const X_REAL_IP: &str = "x-real-ip";
|
||||
/// e.g. Forwarded: for=192.0.2.60;proto=https;by=203.0.113.43
|
||||
const FORWARDED: &str = "forwarded";
|
||||
|
||||
static FOR_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(?i)(?:for=)([^(;|,| )]+)(.*)").expect("operation should succeed"));
|
||||
static PROTO_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(?i)^(;|,| )+(?:proto=)(https|http)").expect("operation should succeed"));
|
||||
static FOR_REGEX: LazyLock<Regex> =
|
||||
LazyLock::new(|| Regex::new(r"(?i)(?:for=)([^(;|,| )]+)(.*)").expect("operation should succeed"));
|
||||
static PROTO_REGEX: LazyLock<Regex> =
|
||||
LazyLock::new(|| Regex::new(r"(?i)^(;|,| )+(?:proto=)(https|http)").expect("operation should succeed"));
|
||||
|
||||
/// Used to disable all processing of the X-Forwarded-For header in source IP discovery.
|
||||
///
|
||||
|
||||
@@ -236,7 +236,8 @@ pub fn match_as_pattern_prefix(pattern: &str, text: &str) -> bool {
|
||||
text.len() <= pattern.len()
|
||||
}
|
||||
|
||||
static ELLIPSES_RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(.*)(\{[0-9A-Fa-f]*\.\.\.[0-9A-Fa-f]*\})(.*)").expect("operation should succeed"));
|
||||
static ELLIPSES_RE: LazyLock<Regex> =
|
||||
LazyLock::new(|| Regex::new(r"(.*)(\{[0-9A-Fa-f]*\.\.\.[0-9A-Fa-f]*\})(.*)").expect("operation should succeed"));
|
||||
|
||||
/// Ellipses constants
|
||||
const OPEN_BRACES: &str = "{";
|
||||
|
||||
Reference in New Issue
Block a user