From aa4de7b9d6b433ddcb9f07618626a79b852e3ed6 Mon Sep 17 00:00:00 2001 From: houseme Date: Sat, 8 Aug 2026 02:39:09 +0800 Subject: [PATCH] perf(utils): avoid metadata key lowercase allocation (#5823) Co-authored-by: heihutu --- crates/utils/src/http/header_compat.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/utils/src/http/header_compat.rs b/crates/utils/src/http/header_compat.rs index d1bd38b82..822450e37 100644 --- a/crates/utils/src/http/header_compat.rs +++ b/crates/utils/src/http/header_compat.rs @@ -48,6 +48,13 @@ pub const SUFFIX_REPLICATION_SSEC_CRC: &str = "replication-ssec-crc"; /// Returns true if the key is object-encryption metadata understood by RustFS or MinIO. /// Case-insensitive for metadata filtering. pub fn is_encryption_metadata_key(key: &str) -> bool { + if key.is_ascii() { + return super::starts_with_ignore_ascii_case(key, RUSTFS_ENCRYPTION_PREFIX) + || super::starts_with_ignore_ascii_case(key, MINIO_ENCRYPTION_PREFIX) + || super::starts_with_ignore_ascii_case(key, MINIO_INTERNAL_ENCRYPTION_PREFIX) + || key.eq_ignore_ascii_case(MINIO_INTERNAL_ENCRYPTED_MULTIPART); + } + let lower = key.to_lowercase(); lower.starts_with(RUSTFS_ENCRYPTION_PREFIX) || lower.starts_with(MINIO_ENCRYPTION_PREFIX) @@ -151,7 +158,9 @@ mod tests { assert!(is_encryption_metadata_key("x-minio-encryption-iv")); assert!(is_encryption_metadata_key("X-Minio-Internal-Server-Side-Encryption-Sealed-Key")); assert!(is_encryption_metadata_key("X-Minio-Internal-Encrypted-Multipart")); + assert!(is_encryption_metadata_key("X-RUSTFS-ENCRYPTION-\u{212A}EY")); assert!(!is_encryption_metadata_key("x-amz-meta-custom")); + assert!(!is_encryption_metadata_key("x-minio-internal-encrypted-multipart-extra")); assert!(!is_encryption_metadata_key("x-rustfs-internal-healing")); }