diff --git a/rustfs/src/storage/ecfs.rs b/rustfs/src/storage/ecfs.rs index 1b125c62..995178c1 100644 --- a/rustfs/src/storage/ecfs.rs +++ b/rustfs/src/storage/ecfs.rs @@ -2264,6 +2264,7 @@ impl S3 for FS { bucket, key, content_length, + content_type, tagging, metadata, version_id, @@ -2336,7 +2337,11 @@ impl S3 for FS { let mut metadata = metadata.unwrap_or_default(); - extract_metadata_from_mime_with_object_name(&req.headers, &mut metadata, Some(&key)); + if let Some(content_type) = content_type { + metadata.insert("content-type".to_string(), content_type.to_string()); + } + + extract_metadata_from_mime_with_object_name(&req.headers, &mut metadata, true, Some(&key)); if let Some(tags) = tagging { metadata.insert(AMZ_OBJECT_TAGGING.to_owned(), tags.to_string()); diff --git a/rustfs/src/storage/options.rs b/rustfs/src/storage/options.rs index 68d8783f..ca3c750d 100644 --- a/rustfs/src/storage/options.rs +++ b/rustfs/src/storage/options.rs @@ -288,16 +288,21 @@ pub fn extract_metadata(headers: &HeaderMap) -> HashMap, metadata: &mut HashMap) { - extract_metadata_from_mime_with_object_name(headers, metadata, None); + extract_metadata_from_mime_with_object_name(headers, metadata, false, None); } /// Extracts metadata from headers and returns it as a HashMap with object name for MIME type detection. pub fn extract_metadata_from_mime_with_object_name( headers: &HeaderMap, metadata: &mut HashMap, + skip_content_type: bool, object_name: Option<&str>, ) { for (k, v) in headers.iter() { + if k.as_str() == "content-type" && skip_content_type { + continue; + } + if let Some(key) = k.as_str().strip_prefix("x-amz-meta-") { if key.is_empty() { continue; @@ -977,7 +982,7 @@ mod tests { let headers = HeaderMap::new(); let mut metadata = HashMap::new(); - extract_metadata_from_mime_with_object_name(&headers, &mut metadata, Some("data/test.parquet")); + extract_metadata_from_mime_with_object_name(&headers, &mut metadata, false, Some("data/test.parquet")); assert_eq!(metadata.get("content-type"), Some(&"application/vnd.apache.parquet".to_string())); } @@ -1001,7 +1006,7 @@ mod tests { let headers = HeaderMap::new(); let mut metadata = HashMap::new(); - extract_metadata_from_mime_with_object_name(&headers, &mut metadata, Some(filename)); + extract_metadata_from_mime_with_object_name(&headers, &mut metadata, false, Some(filename)); assert_eq!( metadata.get("content-type"), @@ -1017,7 +1022,7 @@ mod tests { headers.insert("content-type", HeaderValue::from_static("custom/type")); let mut metadata = HashMap::new(); - extract_metadata_from_mime_with_object_name(&headers, &mut metadata, Some("test.parquet")); + extract_metadata_from_mime_with_object_name(&headers, &mut metadata, false, Some("test.parquet")); // Should preserve existing content-type, not overwrite assert_eq!(metadata.get("content-type"), Some(&"custom/type".to_string()));