Skip to content

Commit

Permalink
feat(services/cos): Added user metadata support for cos service (#5510)
Browse files Browse the repository at this point in the history
Co-authored-by: Xuanwo <[email protected]>
  • Loading branch information
geetanshjuneja and Xuanwo authored Jan 13, 2025
1 parent 41c72d8 commit 5ae1a76
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/src/services/cos/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ impl Access for CosBackend {
stat_has_last_modified: true,
stat_has_content_disposition: true,
stat_has_version: true,
stat_has_user_metadata: true,

read: true,

Expand Down Expand Up @@ -296,6 +297,7 @@ impl Access for CosBackend {
} else {
Some(usize::MAX)
},
write_with_user_metadata: true,

delete: true,
delete_with_version: self.core.enable_versioning,
Expand Down Expand Up @@ -330,6 +332,11 @@ impl Access for CosBackend {
let headers = resp.headers();
let mut meta = parse_into_metadata(path, headers)?;

let user_meta = parse_prefixed_headers(headers, "x-cos-meta-");
if !user_meta.is_empty() {
meta.with_user_metadata(user_meta);
}

if let Some(v) = parse_header_to_str(headers, "x-cos-version-id")? {
meta.set_version(v);
}
Expand Down
14 changes: 14 additions & 0 deletions core/src/services/cos/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ impl CosCore {
req = req.header("x-cos-forbid-overwrite", "true")
}

// Set user metadata headers.
if let Some(user_metadata) = args.user_metadata() {
for (key, value) in user_metadata {
req = req.header(format!("x-cos-meta-{key}"), value)
}
}

let req = req.body(body).map_err(new_request_build_error)?;

Ok(req)
Expand Down Expand Up @@ -387,6 +394,13 @@ impl CosCore {
req = req.header(CACHE_CONTROL, cache_control)
}

// Set user metadata headers.
if let Some(user_metadata) = args.user_metadata() {
for (key, value) in user_metadata {
req = req.header(format!("x-cos-meta-{key}"), value)
}
}

let mut req = req.body(Buffer::new()).map_err(new_request_build_error)?;

self.sign(&mut req).await?;
Expand Down

0 comments on commit 5ae1a76

Please sign in to comment.