Skip to content

Commit

Permalink
feat(core): Add content_encoding to MetaData (#5400)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank-III authored Dec 8, 2024
1 parent 9494b52 commit 7cde1f5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
5 changes: 2 additions & 3 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,15 @@ 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
/// unexpected struct/enum size change.
#[test]
fn assert_size() {
assert_eq!(32, size_of::<Operator>());
assert_eq!(296, size_of::<Entry>());
assert_eq!(272, size_of::<Metadata>());
assert_eq!(320, size_of::<Entry>());
assert_eq!(296, size_of::<Metadata>());
assert_eq!(1, size_of::<EntryMode>());
assert_eq!(24, size_of::<Scheme>());
}
Expand Down
4 changes: 4 additions & 0 deletions core/src/raw/http_util/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ pub fn parse_into_metadata(path: &str, headers: &HeaderMap) -> Result<Metadata>
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);
}
Expand Down
1 change: 1 addition & 0 deletions core/src/services/s3/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions core/src/types/capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions core/src/types/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct Metadata {
content_md5: Option<String>,
content_range: Option<BytesContentRange>,
content_type: Option<String>,
content_encoding: Option<String>,
etag: Option<String>,
last_modified: Option<DateTime<Utc>>,
version: Option<String>,
Expand All @@ -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,
Expand Down Expand Up @@ -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).
Expand Down

0 comments on commit 7cde1f5

Please sign in to comment.