From f57b74376e747f6bb32ebe735c78b1b90a76fd46 Mon Sep 17 00:00:00 2001 From: Frank Wang <1454884738@qq.com> Date: Fri, 6 Dec 2024 14:28:57 +0000 Subject: [PATCH 1/3] feat(core): add `content_encoding` to `MetaData` --- 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 | 17 +++++++++++++++++ 4 files changed, 24 insertions(+) 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..0cba7a27f0bb 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,21 @@ impl Metadata { self } + /// Content Encoding of this entry. + /// + /// Content Encoding is defined by [RFC 9110](https://httpwg.org/specs/rfc9110.html#field.content-encoding). + pub fn content_encoding(&self) -> Option<&str> { + self.content_encoding.as_deref() + } + + /// Set Content Encoding of this entry. + /// + /// Content Encoding is defined by [RFC 9110](https://httpwg.org/specs/rfc9110.html#field.content-encoding). + 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). From 9e56713ac2940691155088afe909770aabefc1a7 Mon Sep 17 00:00:00 2001 From: Frank Wang <1454884738@qq.com> Date: Fri, 6 Dec 2024 14:41:21 +0000 Subject: [PATCH 2/3] fix: assert size of metadata --- core/src/lib.rs | 5 ++--- 1 file changed, 2 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::()); } From 310e3db1d5d74b36a22bffaa4d587cb372dcf309 Mon Sep 17 00:00:00 2001 From: Frank Wang <1454884738@qq.com> Date: Fri, 6 Dec 2024 14:44:53 +0000 Subject: [PATCH 3/3] chore: doc fix --- core/src/types/metadata.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/src/types/metadata.rs b/core/src/types/metadata.rs index 0cba7a27f0bb..c1d4155e1971 100644 --- a/core/src/types/metadata.rs +++ b/core/src/types/metadata.rs @@ -205,15 +205,11 @@ impl Metadata { } /// Content Encoding of this entry. - /// - /// Content Encoding is defined by [RFC 9110](https://httpwg.org/specs/rfc9110.html#field.content-encoding). pub fn content_encoding(&self) -> Option<&str> { self.content_encoding.as_deref() } /// Set Content Encoding of this entry. - /// - /// Content Encoding is defined by [RFC 9110](https://httpwg.org/specs/rfc9110.html#field.content-encoding). pub fn set_content_encoding(&mut self, v: &str) -> &mut Self { self.content_encoding = Some(v.to_string()); self