You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2023/04/19 13:09:41 UTC

[incubator-opendal] branch main updated: add if-match support for OSS (#2034)

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 b6d7e0e4 add if-match support for OSS (#2034)
b6d7e0e4 is described below

commit b6d7e0e410ca2e472c1671cfeb97f3af0b1b577f
Author: Renkai Ge <ga...@gmail.com>
AuthorDate: Wed Apr 19 21:09:36 2023 +0800

    add if-match support for OSS (#2034)
    
    * add if-match support
    
    * add if match for get
---
 core/src/services/oss/backend.rs | 10 ++++++----
 core/src/services/oss/core.rs    | 15 +++++++++++++--
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/core/src/services/oss/backend.rs b/core/src/services/oss/backend.rs
index c314586c..77f9aefa 100644
--- a/core/src/services/oss/backend.rs
+++ b/core/src/services/oss/backend.rs
@@ -392,7 +392,7 @@ impl Accessor for OssBackend {
     async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> {
         let resp = self
             .core
-            .oss_get_object(path, args.range(), args.if_none_match())
+            .oss_get_object(path, args.range(), args.if_match(), args.if_none_match())
             .await?;
 
         let status = resp.status();
@@ -434,7 +434,7 @@ impl Accessor for OssBackend {
 
         let resp = self
             .core
-            .oss_head_object(path, args.if_none_match())
+            .oss_head_object(path, args.if_match(), args.if_none_match())
             .await?;
 
         let status = resp.status();
@@ -479,10 +479,12 @@ impl Accessor for OssBackend {
     async fn presign(&self, path: &str, args: OpPresign) -> Result<RpPresign> {
         // We will not send this request out, just for signing.
         let mut req = match args.operation() {
-            PresignOperation::Stat(_) => self.core.oss_head_object_request(path, true, None)?,
+            PresignOperation::Stat(_) => {
+                self.core.oss_head_object_request(path, true, None, None)?
+            }
             PresignOperation::Read(v) => {
                 self.core
-                    .oss_get_object_request(path, v.range(), true, None)?
+                    .oss_get_object_request(path, v.range(), true, None, None)?
             }
             PresignOperation::Write(v) => self.core.oss_put_object_request(
                 path,
diff --git a/core/src/services/oss/core.rs b/core/src/services/oss/core.rs
index 6922869c..8626e8e3 100644
--- a/core/src/services/oss/core.rs
+++ b/core/src/services/oss/core.rs
@@ -24,6 +24,7 @@ use http::header::CACHE_CONTROL;
 use http::header::CONTENT_DISPOSITION;
 use http::header::CONTENT_LENGTH;
 use http::header::CONTENT_TYPE;
+use http::header::IF_MATCH;
 use http::header::IF_NONE_MATCH;
 use http::header::RANGE;
 use http::Request;
@@ -148,6 +149,7 @@ impl OssCore {
         path: &str,
         range: BytesRange,
         is_presign: bool,
+        if_match: Option<&str>,
         if_none_match: Option<&str>,
     ) -> Result<Request<AsyncBody>> {
         let p = build_abs_path(&self.root, path);
@@ -164,6 +166,9 @@ impl OssCore {
             req = req.header("x-oss-range-behavior", "standard");
         }
 
+        if let Some(if_match) = if_match {
+            req = req.header(IF_MATCH, if_match)
+        }
         if let Some(if_none_match) = if_none_match {
             req = req.header(IF_NONE_MATCH, if_none_match);
         }
@@ -192,6 +197,7 @@ impl OssCore {
         &self,
         path: &str,
         is_presign: bool,
+        if_match: Option<&str>,
         if_none_match: Option<&str>,
     ) -> Result<Request<AsyncBody>> {
         let p = build_abs_path(&self.root, path);
@@ -199,6 +205,9 @@ impl OssCore {
         let url = format!("{}/{}", endpoint, percent_encode_path(&p));
 
         let mut req = Request::head(&url);
+        if let Some(if_match) = if_match {
+            req = req.header(IF_MATCH, if_match)
+        }
         if let Some(if_none_match) = if_none_match {
             req = req.header(IF_NONE_MATCH, if_none_match);
         }
@@ -239,9 +248,10 @@ impl OssCore {
         &self,
         path: &str,
         range: BytesRange,
+        if_match: Option<&str>,
         if_none_match: Option<&str>,
     ) -> Result<Response<IncomingAsyncBody>> {
-        let mut req = self.oss_get_object_request(path, range, false, if_none_match)?;
+        let mut req = self.oss_get_object_request(path, range, false, if_match, if_none_match)?;
 
         self.sign(&mut req).await?;
         self.send(req).await
@@ -250,9 +260,10 @@ impl OssCore {
     pub async fn oss_head_object(
         &self,
         path: &str,
+        if_match: Option<&str>,
         if_none_match: Option<&str>,
     ) -> Result<Response<IncomingAsyncBody>> {
-        let mut req = self.oss_head_object_request(path, false, if_none_match)?;
+        let mut req = self.oss_head_object_request(path, false, if_match, if_none_match)?;
 
         self.sign(&mut req).await?;
         self.send(req).await