From 7cde1f585bc00e42c459a463956b6bc260d2eaaa Mon Sep 17 00:00:00 2001 From: frankwang <73262844+Frank-III@users.noreply.github.com> Date: Sun, 8 Dec 2024 00:51:38 -0600 Subject: [PATCH] feat(core): Add `content_encoding` to `MetaData` (#5400) --- core/src/lib.rs | 5 ++--- core/src/raw/http_util/header.rs | 4 ++++ core/src/services/s3/backend.rs | 1 + core/src/types/capability.rs | 2 ++ core/src/types/metadata.rs | 13 +++++++++++++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/core/src/lib.rs b/core/src/lib.rs index 7a7f6eae18ff..8f989adf89a5 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -144,7 +144,6 @@ mod tests { use std::mem::size_of; use super::*; - /// This is not a real test case. /// /// We assert our public structs here to make sure we don't introduce @@ -152,8 +151,8 @@ mod tests { #[test] fn assert_size() { assert_eq!(32, size_of::()); - assert_eq!(296, size_of::()); - assert_eq!(272, size_of::()); + assert_eq!(320, size_of::()); + assert_eq!(296, size_of::()); assert_eq!(1, size_of::()); assert_eq!(24, size_of::()); } diff --git a/core/src/raw/http_util/header.rs b/core/src/raw/http_util/header.rs index 6c8ba65dbab9..2da77a4b08dc 100644 --- a/core/src/raw/http_util/header.rs +++ b/core/src/raw/http_util/header.rs @@ -173,6 +173,10 @@ pub fn parse_into_metadata(path: &str, headers: &HeaderMap) -> Result m.set_content_type(v); } + if let Some(v) = parse_content_encoding(headers)? { + m.set_content_encoding(v); + } + if let Some(v) = parse_content_range(headers)? { m.set_content_range(v); } diff --git a/core/src/services/s3/backend.rs b/core/src/services/s3/backend.rs index 52f311415489..8ffd6b7ab7b7 100644 --- a/core/src/services/s3/backend.rs +++ b/core/src/services/s3/backend.rs @@ -923,6 +923,7 @@ impl Access for S3Backend { .set_name(&self.core.bucket) .set_native_capability(Capability { stat: true, + stat_has_content_encoding: true, stat_with_if_match: true, stat_with_if_none_match: true, stat_with_override_cache_control: !self.core.disable_stat_with_override, diff --git a/core/src/types/capability.rs b/core/src/types/capability.rs index 2fdf56e87ce3..42c064368180 100644 --- a/core/src/types/capability.rs +++ b/core/src/types/capability.rs @@ -90,6 +90,8 @@ pub struct Capability { pub stat_has_content_range: bool, /// Indicates whether content type information is available in stat response pub stat_has_content_type: bool, + /// Indicates whether content encoding information is available in stat response + pub stat_has_content_encoding: bool, /// Indicates whether entity tag is available in stat response pub stat_has_etag: bool, /// Indicates whether last modified timestamp is available in stat response diff --git a/core/src/types/metadata.rs b/core/src/types/metadata.rs index 7314f25db5fd..c1d4155e1971 100644 --- a/core/src/types/metadata.rs +++ b/core/src/types/metadata.rs @@ -39,6 +39,7 @@ pub struct Metadata { content_md5: Option, content_range: Option, content_type: Option, + content_encoding: Option, etag: Option, last_modified: Option>, version: Option, @@ -56,6 +57,7 @@ impl Metadata { content_length: None, content_md5: None, content_type: None, + content_encoding: None, content_range: None, last_modified: None, etag: None, @@ -202,6 +204,17 @@ impl Metadata { self } + /// Content Encoding of this entry. + pub fn content_encoding(&self) -> Option<&str> { + self.content_encoding.as_deref() + } + + /// Set Content Encoding of this entry. + pub fn set_content_encoding(&mut self, v: &str) -> &mut Self { + self.content_encoding = Some(v.to_string()); + self + } + /// Content Range of this entry. /// /// Content Range is defined by [RFC 9110](https://httpwg.org/specs/rfc9110.html#field.content-range).