Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(services/cos): Added user metadata support for cos service #5510

Merged
merged 14 commits into from
Jan 13, 2025
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
Loading