diff --git a/core/src/services/cos/backend.rs b/core/src/services/cos/backend.rs index 86d7e342ca3..28336e55f23 100644 --- a/core/src/services/cos/backend.rs +++ b/core/src/services/cos/backend.rs @@ -257,6 +257,7 @@ impl Access for CosBackend { stat_has_content_md5: true, stat_has_last_modified: true, stat_has_content_disposition: true, + stat_has_user_metadata: true, read: true, @@ -284,6 +285,7 @@ impl Access for CosBackend { } else { Some(usize::MAX) }, + write_with_user_metadata: true, delete: true, copy: true, @@ -311,7 +313,15 @@ impl Access for CosBackend { let status = resp.status(); match status { - StatusCode::OK => parse_into_metadata(path, resp.headers()).map(RpStat::new), + StatusCode::OK => { + 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); + } + Ok(RpStat::new(meta)) + } _ => Err(parse_error(resp)), } } diff --git a/core/src/services/cos/core.rs b/core/src/services/cos/core.rs index 4d28b268895..9d3adcc6948 100644 --- a/core/src/services/cos/core.rs +++ b/core/src/services/cos/core.rs @@ -184,6 +184,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) @@ -345,6 +352,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?;