Skip to content

Commit

Permalink
feat(services/gcs): Impl content-encoding support for GCS stat, write…
Browse files Browse the repository at this point in the history
… and presign (#5610)
  • Loading branch information
wlinna authored Feb 7, 2025
1 parent 94dc47f commit 30dd2a8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/src/services/gcs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ impl Access for GcsBackend {
stat_has_content_md5: true,
stat_has_content_length: true,
stat_has_content_type: true,
stat_has_content_encoding: true,
stat_has_last_modified: true,
stat_has_user_metadata: true,

Expand All @@ -374,6 +375,7 @@ impl Access for GcsBackend {
write_can_empty: true,
write_can_multi: true,
write_with_content_type: true,
write_with_content_encoding: true,
write_with_user_metadata: true,
write_with_if_not_exists: true,

Expand Down Expand Up @@ -442,6 +444,10 @@ impl Access for GcsBackend {
m.set_content_type(&meta.content_type);
}

if !meta.content_encoding.is_empty() {
m.set_content_encoding(&meta.content_encoding);
}

m.set_last_modified(parse_datetime_from_rfc3339(&meta.updated)?);

if !meta.metadata.is_empty() {
Expand Down Expand Up @@ -554,6 +560,10 @@ struct GetObjectJsonResponse {
///
/// For example: `"contentType": "image/png",`
content_type: String,
/// Content encoding of this object
///
/// For example: "contentEncoding": "br"
content_encoding: String,
/// Custom metadata of this object.
///
/// For example: `"metadata" : { "my-key": "my-value" }`
Expand All @@ -576,6 +586,7 @@ mod tests {
"generation": "1660563214863653",
"metageneration": "1",
"contentType": "image/png",
"contentEncoding": "br",
"storageClass": "STANDARD",
"size": "56535",
"md5Hash": "fHcEH1vPwA6eTPqxuasXcg==",
Expand All @@ -597,6 +608,7 @@ mod tests {
assert_eq!(meta.md5_hash, "fHcEH1vPwA6eTPqxuasXcg==");
assert_eq!(meta.etag, "CKWasoTgyPkCEAE=");
assert_eq!(meta.content_type, "image/png");
assert_eq!(meta.content_encoding, "br".to_string());
assert_eq!(
meta.metadata,
HashMap::from_iter([("location".to_string(), "everywhere".to_string())])
Expand Down
8 changes: 8 additions & 0 deletions core/src/services/gcs/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::time::Duration;
use backon::ExponentialBuilder;
use backon::Retryable;
use bytes::Bytes;
use http::header::CONTENT_ENCODING;
use http::header::CONTENT_LENGTH;
use http::header::CONTENT_TYPE;
use http::header::HOST;
Expand Down Expand Up @@ -267,6 +268,7 @@ impl GcsCore {
storage_class: self.default_storage_class.as_deref(),
cache_control: op.cache_control(),
content_type: op.content_type(),
content_encoding: op.content_encoding(),
metadata: op.user_metadata(),
};

Expand Down Expand Up @@ -347,6 +349,10 @@ impl GcsCore {
req = req.header(CONTENT_TYPE, content_type);
}

if let Some(content_encoding) = args.content_encoding() {
req = req.header(CONTENT_ENCODING, content_encoding);
}

if let Some(acl) = &self.predefined_acl {
req = req.header(X_GOOG_ACL, acl);
}
Expand Down Expand Up @@ -639,6 +645,8 @@ pub struct InsertRequestMetadata<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
content_type: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
content_encoding: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
storage_class: Option<&'a str>,
#[serde(skip_serializing_if = "Option::is_none")]
cache_control: Option<&'a str>,
Expand Down
5 changes: 5 additions & 0 deletions core/src/types/operator/operator_futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ impl<F: Future<Output = Result<PresignedRequest>>> FuturePresignWrite<F> {
self.map(|(args, dur)| (args.with_content_disposition(v), dur))
}

/// Set the content encoding of the operation
pub fn content_encoding(self, v: &str) -> Self {
self.map(|(args, dur)| (args.with_content_encoding(v), dur))
}

/// Set the content type of option
pub fn cache_control(self, v: &str) -> Self {
self.map(|(args, dur)| (args.with_cache_control(v), dur))
Expand Down

0 comments on commit 30dd2a8

Please sign in to comment.