This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
The following commit(s) were added to refs/heads/main by this push:
new d797f0541 refactor(services/oss): Refactor `oss_put_object` signatures
by using OpWrite (#3080)
d797f0541 is described below
commit d797f054195f7d3bc9f9870665b1a581f6b998ee
Author: Chengqian Du <[email protected]>
AuthorDate: Fri Sep 15 11:15:16 2023 +0800
refactor(services/oss): Refactor `oss_put_object` signatures by using
OpWrite (#3080)
* refactor(services/oss): Refactor oss_put_object signatures by using
OpWrite
* Refactor: cargo fmt checks
---
core/src/services/oss/backend.rs | 15 +++++----------
core/src/services/oss/core.rs | 24 ++++++------------------
core/src/services/oss/writer.rs | 12 +++---------
3 files changed, 14 insertions(+), 37 deletions(-)
diff --git a/core/src/services/oss/backend.rs b/core/src/services/oss/backend.rs
index b90fe8f2c..1e32d8ea0 100644
--- a/core/src/services/oss/backend.rs
+++ b/core/src/services/oss/backend.rs
@@ -437,7 +437,7 @@ impl Accessor for OssBackend {
async fn create_dir(&self, path: &str, _: OpCreateDir) ->
Result<RpCreateDir> {
let resp = self
.core
- .oss_put_object(path, None, None, None, None, AsyncBody::Empty)
+ .oss_put_object(path, None, &OpWrite::default(), AsyncBody::Empty)
.await?;
let status = resp.status();
@@ -556,15 +556,10 @@ impl Accessor for OssBackend {
v.if_none_match(),
v.override_content_disposition(),
)?,
- PresignOperation::Write(v) => self.core.oss_put_object_request(
- path,
- None,
- v.content_type(),
- v.content_disposition(),
- v.cache_control(),
- AsyncBody::Empty,
- true,
- )?,
+ PresignOperation::Write(v) => {
+ self.core
+ .oss_put_object_request(path, None, v, AsyncBody::Empty,
true)?
+ }
};
self.core.sign_query(&mut req, args.expire()).await?;
diff --git a/core/src/services/oss/core.rs b/core/src/services/oss/core.rs
index a81db97fa..25e870f99 100644
--- a/core/src/services/oss/core.rs
+++ b/core/src/services/oss/core.rs
@@ -152,9 +152,7 @@ impl OssCore {
&self,
path: &str,
size: Option<u64>,
- content_type: Option<&str>,
- content_disposition: Option<&str>,
- cache_control: Option<&str>,
+ args: &OpWrite,
body: AsyncBody,
is_presign: bool,
) -> Result<Request<AsyncBody>> {
@@ -166,15 +164,15 @@ impl OssCore {
req = req.header(CONTENT_LENGTH, size.unwrap_or_default());
- if let Some(mime) = content_type {
+ if let Some(mime) = args.content_type() {
req = req.header(CONTENT_TYPE, mime);
}
- if let Some(pos) = content_disposition {
+ if let Some(pos) = args.content_disposition() {
req = req.header(CONTENT_DISPOSITION, pos);
}
- if let Some(cache_control) = cache_control {
+ if let Some(cache_control) = args.cache_control() {
req = req.header(CACHE_CONTROL, cache_control)
}
@@ -376,20 +374,10 @@ impl OssCore {
&self,
path: &str,
size: Option<u64>,
- content_type: Option<&str>,
- content_disposition: Option<&str>,
- cache_control: Option<&str>,
+ args: &OpWrite,
body: AsyncBody,
) -> Result<Response<IncomingAsyncBody>> {
- let mut req = self.oss_put_object_request(
- path,
- size,
- content_type,
- content_disposition,
- cache_control,
- body,
- false,
- )?;
+ let mut req = self.oss_put_object_request(path, size, args, body,
false)?;
self.sign(&mut req).await?;
self.send(req).await
diff --git a/core/src/services/oss/writer.rs b/core/src/services/oss/writer.rs
index 296055e29..8405f78e7 100644
--- a/core/src/services/oss/writer.rs
+++ b/core/src/services/oss/writer.rs
@@ -48,15 +48,9 @@ impl OssWriter {
#[async_trait]
impl oio::MultipartUploadWrite for OssWriter {
async fn write_once(&self, size: u64, body: AsyncBody) -> Result<()> {
- let mut req = self.core.oss_put_object_request(
- &self.path,
- Some(size),
- self.op.content_type(),
- self.op.content_disposition(),
- self.op.cache_control(),
- body,
- false,
- )?;
+ let mut req =
+ self.core
+ .oss_put_object_request(&self.path, Some(size), &self.op,
body, false)?;
self.core.sign(&mut req).await?;