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 c565968c feat: add if_none_match support for azblob (#2035)
c565968c is described below

commit c565968cd7b74a5141a2b424eb059a0c6f827120
Author: Yuxuan <[email protected]>
AuthorDate: Wed Apr 19 14:27:13 2023 +0800

    feat: add if_none_match support for azblob (#2035)
    
    * feat: if_none_match for azblob
    
    Signed-off-by: Yuxuan <[email protected]>
    
    * feat: if_none_match for azblob
    
    Signed-off-by: Yuxuan <[email protected]>
    
    * fix: variable naming practice
    
    Signed-off-by: Yuxuan <[email protected]>
    
    ---------
    
    Signed-off-by: Yuxuan <[email protected]>
---
 core/src/services/azblob/backend.rs | 12 +++++++++---
 core/src/services/azblob/core.rs    | 13 ++++++++++++-
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/core/src/services/azblob/backend.rs 
b/core/src/services/azblob/backend.rs
index 5daa104e..dfd7ca18 100644
--- a/core/src/services/azblob/backend.rs
+++ b/core/src/services/azblob/backend.rs
@@ -482,7 +482,10 @@ impl Accessor for AzblobBackend {
     }
 
     async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, 
Self::Reader)> {
-        let resp = self.core.azblob_get_blob(path, args.range()).await?;
+        let resp = self
+            .core
+            .azblob_get_blob(path, args.range(), args.if_none_match())
+            .await?;
 
         let status = resp.status();
 
@@ -524,13 +527,16 @@ impl Accessor for AzblobBackend {
         }
     }
 
-    async fn stat(&self, path: &str, _: OpStat) -> Result<RpStat> {
+    async fn stat(&self, path: &str, args: OpStat) -> Result<RpStat> {
         // Stat root always returns a DIR.
         if path == "/" {
             return Ok(RpStat::new(Metadata::new(EntryMode::DIR)));
         }
 
-        let resp = self.core.azblob_get_blob_properties(path).await?;
+        let resp = self
+            .core
+            .azblob_get_blob_properties(path, args.if_none_match())
+            .await?;
 
         let status = resp.status();
 
diff --git a/core/src/services/azblob/core.rs b/core/src/services/azblob/core.rs
index 78aac286..74a2e8d3 100644
--- a/core/src/services/azblob/core.rs
+++ b/core/src/services/azblob/core.rs
@@ -24,6 +24,7 @@ use std::str::FromStr;
 use http::header::HeaderName;
 use http::header::CONTENT_LENGTH;
 use http::header::CONTENT_TYPE;
+use http::header::IF_NONE_MATCH;
 use http::Request;
 use http::Response;
 use http::Uri;
@@ -100,6 +101,7 @@ impl AzblobCore {
         &self,
         path: &str,
         range: BytesRange,
+        if_none_match: Option<&str>,
     ) -> Result<Response<IncomingAsyncBody>> {
         let p = build_abs_path(&self.root, path);
 
@@ -126,6 +128,10 @@ impl AzblobCore {
             req = req.header(http::header::RANGE, range.to_header());
         }
 
+        if let Some(if_none_match) = if_none_match {
+            req = req.header(IF_NONE_MATCH, if_none_match);
+        }
+
         let mut req = req
             .body(AsyncBody::Empty)
             .map_err(new_request_build_error)?;
@@ -172,6 +178,7 @@ impl AzblobCore {
     pub async fn azblob_get_blob_properties(
         &self,
         path: &str,
+        if_none_match: Option<&str>,
     ) -> Result<Response<IncomingAsyncBody>> {
         let p = build_abs_path(&self.root, path);
 
@@ -182,7 +189,11 @@ impl AzblobCore {
             percent_encode_path(&p)
         );
 
-        let req = Request::head(&url);
+        let mut req = Request::head(&url);
+
+        if let Some(if_none_match) = if_none_match {
+            req = req.header(IF_NONE_MATCH, if_none_match);
+        }
 
         let mut req = req
             .body(AsyncBody::Empty)

Reply via email to