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 41a3ed993 feat: gcs insert object support cache control (#2974)
41a3ed993 is described below

commit 41a3ed9935f7f124fb6e22daace965543d3db6fe
Author: wangxiaolei <[email protected]>
AuthorDate: Thu Aug 31 23:02:34 2023 +0800

    feat: gcs insert object support cache control (#2974)
    
    feat: gcs multipart upload support cache control
---
 core/src/services/gcs/backend.rs |  9 ++++++---
 core/src/services/gcs/core.rs    | 20 +++++++++++++++-----
 core/src/services/gcs/writer.rs  |  2 +-
 3 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/core/src/services/gcs/backend.rs b/core/src/services/gcs/backend.rs
index b4a844ea6..dc760cb15 100644
--- a/core/src/services/gcs/backend.rs
+++ b/core/src/services/gcs/backend.rs
@@ -385,9 +385,12 @@ impl Accessor for GcsBackend {
     }
 
     async fn create_dir(&self, path: &str, _: OpCreateDir) -> 
Result<RpCreateDir> {
-        let mut req = self
-            .core
-            .gcs_insert_object_request(path, Some(0), None, AsyncBody::Empty)?;
+        let mut req = self.core.gcs_insert_object_request(
+            path,
+            Some(0),
+            &OpWrite::default(),
+            AsyncBody::Empty,
+        )?;
 
         self.core.sign(&mut req).await?;
 
diff --git a/core/src/services/gcs/core.rs b/core/src/services/gcs/core.rs
index 9a5a35c48..5ef8f04c3 100644
--- a/core/src/services/gcs/core.rs
+++ b/core/src/services/gcs/core.rs
@@ -15,6 +15,7 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use std::collections::HashMap;
 use std::fmt::Debug;
 use std::fmt::Formatter;
 use std::fmt::Write;
@@ -231,7 +232,7 @@ impl GcsCore {
         &self,
         path: &str,
         size: Option<u64>,
-        content_type: Option<&str>,
+        op: &OpWrite,
         body: AsyncBody,
     ) -> Result<Request<AsyncBody>> {
         let p = build_abs_path(&self.root, path);
@@ -256,7 +257,16 @@ impl GcsCore {
 
         req = req.header(CONTENT_LENGTH, size.unwrap_or_default());
 
-        if let Some(storage_class) = &self.default_storage_class {
+        let mut meta_data = HashMap::new();
+        if let Some(content_type) = op.content_type() {
+            meta_data.insert("storageClass".to_string(), 
content_type.to_string());
+        }
+
+        if let Some(cache_control) = op.cache_control() {
+            meta_data.insert("cacheControl".to_string(), 
cache_control.to_string());
+        }
+
+        if !meta_data.is_empty() {
             let mut multipart = Multipart::new();
 
             multipart = multipart.part(
@@ -265,12 +275,12 @@ impl GcsCore {
                         CONTENT_TYPE,
                         "application/json; charset=UTF-8".parse().unwrap(),
                     )
-                    .content(json!({"storageClass": 
storage_class}).to_string()),
+                    .content(json!(meta_data).to_string()),
             );
 
             let mut media_part = FormDataPart::new("media").header(
                 CONTENT_TYPE,
-                content_type
+                op.content_type()
                     .unwrap_or("application/octet-stream")
                     .parse()
                     .unwrap(),
@@ -291,7 +301,7 @@ impl GcsCore {
             let req = multipart.apply(Request::post(url))?;
             Ok(req)
         } else {
-            if let Some(content_type) = content_type {
+            if let Some(content_type) = op.content_type() {
                 req = req.header(CONTENT_TYPE, content_type);
             }
 
diff --git a/core/src/services/gcs/writer.rs b/core/src/services/gcs/writer.rs
index 236016294..e6cd8703c 100644
--- a/core/src/services/gcs/writer.rs
+++ b/core/src/services/gcs/writer.rs
@@ -56,7 +56,7 @@ impl GcsWriter {
         let mut req = self.core.gcs_insert_object_request(
             &percent_encode_path(&self.path),
             Some(size),
-            self.op.content_type(),
+            &self.op,
             body,
         )?;
 

Reply via email to