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 989ddb14 feat(services/oss): add oss cache-control header support 
(#1986)
989ddb14 is described below

commit 989ddb1458e01645981d09c38f86413249514424
Author: Yuexun Jiang <[email protected]>
AuthorDate: Fri Apr 14 15:54:52 2023 +0800

    feat(services/oss): add oss cache-control header support (#1986)
---
 core/src/services/oss/backend.rs |  5 +++--
 core/src/services/oss/core.rs    | 23 +++++++++++++++++++++--
 core/src/services/oss/writer.rs  |  1 +
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/core/src/services/oss/backend.rs b/core/src/services/oss/backend.rs
index 5fd87b9f..5bb24bc7 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<RpCreate> {
         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 998f19f6..4f8d11ce 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<usize>,
         content_type: Option<&str>,
         content_disposition: Option<&str>,
+        cache_control: Option<&str>,
         body: AsyncBody,
         is_presign: bool,
     ) -> Result<Request<AsyncBody>> {
@@ -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<usize>,
         content_type: Option<&str>,
         content_disposition: Option<&str>,
+        cache_control: Option<&str>,
         body: AsyncBody,
     ) -> Result<Response<IncomingAsyncBody>> {
         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<Response<IncomingAsyncBody>> {
+    pub async fn oss_initiate_upload(
+        &self,
+        path: &str,
+        args: &OpWrite,
+    ) -> Result<Response<IncomingAsyncBody>> {
+        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<Request<AsyncBody>> {
@@ -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 08eb781e..3c56226c 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,
         )?;

Reply via email to