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 6c3318fc0 refactor(services/http): Rewrite `http` methods signature by 
using OpRead/OpStat (#3083)
6c3318fc0 is described below

commit 6c3318fc04f7cb7540e387b6e4d3bd96b031dd6d
Author: miro <[email protected]>
AuthorDate: Fri Sep 15 13:58:30 2023 +0800

    refactor(services/http): Rewrite `http` methods signature by using 
OpRead/OpStat (#3083)
    
    * refactor(services/http): Rewrite http methods signature using 
OpRead/OpStat
    
    * chore(services/http): format backend.rs
---
 core/src/services/http/backend.rs | 35 ++++++++++-------------------------
 1 file changed, 10 insertions(+), 25 deletions(-)

diff --git a/core/src/services/http/backend.rs 
b/core/src/services/http/backend.rs
index 37048748f..af50631cc 100644
--- a/core/src/services/http/backend.rs
+++ b/core/src/services/http/backend.rs
@@ -232,9 +232,7 @@ impl Accessor for HttpBackend {
     }
 
     async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, 
Self::Reader)> {
-        let resp = self
-            .http_get(path, args.range(), args.if_match(), 
args.if_none_match())
-            .await?;
+        let resp = self.http_get(path, &args).await?;
 
         let status = resp.status();
 
@@ -253,9 +251,7 @@ impl Accessor for HttpBackend {
             return Ok(RpStat::new(Metadata::new(EntryMode::DIR)));
         }
 
-        let resp = self
-            .http_head(path, args.if_match(), args.if_none_match())
-            .await?;
+        let resp = self.http_head(path, &args).await?;
 
         let status = resp.status();
 
@@ -272,24 +268,18 @@ impl Accessor for HttpBackend {
 }
 
 impl HttpBackend {
-    async fn http_get(
-        &self,
-        path: &str,
-        range: BytesRange,
-        if_match: Option<&str>,
-        if_none_match: Option<&str>,
-    ) -> Result<Response<IncomingAsyncBody>> {
+    async fn http_get(&self, path: &str, args: &OpRead) -> 
Result<Response<IncomingAsyncBody>> {
         let p = build_rooted_abs_path(&self.root, path);
 
         let url = format!("{}{}", self.endpoint, percent_encode_path(&p));
 
         let mut req = Request::get(&url);
 
-        if let Some(if_match) = if_match {
+        if let Some(if_match) = args.if_match() {
             req = req.header(IF_MATCH, if_match);
         }
 
-        if let Some(if_none_match) = if_none_match {
+        if let Some(if_none_match) = args.if_none_match() {
             req = req.header(IF_NONE_MATCH, if_none_match);
         }
 
@@ -297,8 +287,8 @@ impl HttpBackend {
             req = req.header(header::AUTHORIZATION, auth.clone())
         }
 
-        if !range.is_full() {
-            req = req.header(header::RANGE, range.to_header());
+        if !args.range().is_full() {
+            req = req.header(header::RANGE, args.range().to_header());
         }
 
         let req = req
@@ -308,23 +298,18 @@ impl HttpBackend {
         self.client.send(req).await
     }
 
-    async fn http_head(
-        &self,
-        path: &str,
-        if_match: Option<&str>,
-        if_none_match: Option<&str>,
-    ) -> Result<Response<IncomingAsyncBody>> {
+    async fn http_head(&self, path: &str, args: &OpStat) -> 
Result<Response<IncomingAsyncBody>> {
         let p = build_rooted_abs_path(&self.root, path);
 
         let url = format!("{}{}", self.endpoint, percent_encode_path(&p));
 
         let mut req = Request::head(&url);
 
-        if let Some(if_match) = if_match {
+        if let Some(if_match) = args.if_match() {
             req = req.header(IF_MATCH, if_match);
         }
 
-        if let Some(if_none_match) = if_none_match {
+        if let Some(if_none_match) = args.if_none_match() {
             req = req.header(IF_NONE_MATCH, if_none_match);
         }
 

Reply via email to