in core/src/services/oss/core.rs [171:219]
fn insert_metadata_headers(
&self,
mut req: http::request::Builder,
size: Option<u64>,
args: &OpWrite,
) -> Result<http::request::Builder> {
req = req.header(CONTENT_LENGTH, size.unwrap_or_default());
if let Some(mime) = args.content_type() {
req = req.header(CONTENT_TYPE, mime);
}
if let Some(pos) = args.content_disposition() {
req = req.header(CONTENT_DISPOSITION, pos);
}
if let Some(cache_control) = args.cache_control() {
req = req.header(CACHE_CONTROL, cache_control);
}
// TODO: disable if not exists while version has been enabled.
//
// Specifies whether the object that is uploaded by calling the PutObject operation
// overwrites the existing object that has the same name. When versioning is enabled
// or suspended for the bucket to which you want to upload the object, the
// x-oss-forbid-overwrite header does not take effect. In this case, the object that
// is uploaded by calling the PutObject operation overwrites the existing object that
// has the same name.
//
// ref: https://www.alibabacloud.com/help/en/oss/developer-reference/putobject?spm=a2c63.p38356.0.0.39ef75e93o0Xtz
if args.if_not_exists() {
req = req.header(X_OSS_FORBID_OVERWRITE, "true");
}
if let Some(user_metadata) = args.user_metadata() {
for (key, value) in user_metadata {
// before insert user defined metadata header, add prefix to the header name
if !self.check_user_metadata_key(key) {
return Err(Error::new(
ErrorKind::Unsupported,
"the format of the user metadata key is invalid, please refer the document",
));
}
req = req.header(format!("{X_OSS_META_PREFIX}{key}"), value)
}
}
Ok(req)
}