diff --git a/core/src/services/oss/backend.rs b/core/src/services/oss/backend.rs index 5fd87b9fbb37..5bb24bc712ef 100644 --- a/core/src/services/oss/backend.rs +++ b/core/src/services/oss/backend.rs @@ -374,7 +374,7 @@ impl Accessor for OssBackend { async fn create(&self, path: &str, _: OpCreate) -> Result { let resp = self .core - .oss_put_object(path, None, None, None, AsyncBody::Empty) + .oss_put_object(path, None, None, None, None, AsyncBody::Empty) .await?; let status = resp.status(); @@ -403,7 +403,7 @@ impl Accessor for OssBackend { async fn write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, Self::Writer)> { let upload_id = if args.append() { - let resp = self.core.oss_initiate_upload(path).await?; + let resp = self.core.oss_initiate_upload(path, &args).await?; match resp.status() { StatusCode::OK => { let bs = resp.into_body().bytes().await?; @@ -494,6 +494,7 @@ impl Accessor for OssBackend { None, v.content_type(), v.content_disposition(), + v.cache_control(), AsyncBody::Empty, true, )?, diff --git a/core/src/services/oss/core.rs b/core/src/services/oss/core.rs index 998f19f60a7c..4f8d11ceebf6 100644 --- a/core/src/services/oss/core.rs +++ b/core/src/services/oss/core.rs @@ -20,6 +20,7 @@ use std::fmt::Formatter; use std::time::Duration; use bytes::Bytes; +use http::header::CACHE_CONTROL; use http::header::CONTENT_DISPOSITION; use http::header::CONTENT_LENGTH; use http::header::CONTENT_TYPE; @@ -32,6 +33,7 @@ use reqsign::AliyunOssSigner; use serde::Deserialize; use serde::Serialize; +use crate::ops::OpWrite; use crate::raw::*; use crate::*; @@ -105,12 +107,14 @@ impl OssCore { } impl OssCore { + #[allow(clippy::too_many_arguments)] pub fn oss_put_object_request( &self, path: &str, size: Option, content_type: Option<&str>, content_disposition: Option<&str>, + cache_control: Option<&str>, body: AsyncBody, is_presign: bool, ) -> Result> { @@ -130,6 +134,10 @@ impl OssCore { req = req.header(CONTENT_DISPOSITION, pos); } + if let Some(cache_control) = cache_control { + req = req.header(CACHE_CONTROL, cache_control) + } + let req = req.body(body).map_err(new_request_build_error)?; Ok(req) } @@ -241,6 +249,7 @@ impl OssCore { size: Option, content_type: Option<&str>, content_disposition: Option<&str>, + cache_control: Option<&str>, body: AsyncBody, ) -> Result> { let mut req = self.oss_put_object_request( @@ -248,6 +257,7 @@ impl OssCore { size, content_type, content_disposition, + cache_control, body, false, )?; @@ -341,9 +351,14 @@ impl OssCore { } } - pub async fn oss_initiate_upload(&self, path: &str) -> Result> { + pub async fn oss_initiate_upload( + &self, + path: &str, + args: &OpWrite, + ) -> Result> { + let cache_control = args.cache_control(); let req = self - .oss_initiate_upload_request(path, None, None, AsyncBody::Empty, false) + .oss_initiate_upload_request(path, None, None, cache_control, AsyncBody::Empty, false) .await?; self.send(req).await } @@ -354,6 +369,7 @@ impl OssCore { path: &str, content_type: Option<&str>, content_disposition: Option<&str>, + cache_control: Option<&str>, body: AsyncBody, is_presign: bool, ) -> Result> { @@ -367,6 +383,9 @@ impl OssCore { if let Some(disposition) = content_disposition { req = req.header(CONTENT_DISPOSITION, disposition); } + if let Some(cache_control) = cache_control { + req = req.header(CACHE_CONTROL, cache_control); + } let mut req = req.body(body).map_err(new_request_build_error)?; self.sign(&mut req).await?; diff --git a/core/src/services/oss/writer.rs b/core/src/services/oss/writer.rs index b306daad7c02..c5bd010e1d3c 100644 --- a/core/src/services/oss/writer.rs +++ b/core/src/services/oss/writer.rs @@ -56,6 +56,7 @@ impl oio::Write for OssWriter { Some(bs.len()), self.op.content_type(), self.op.content_disposition(), + self.op.cache_control(), AsyncBody::Bytes(bs), false, )?;