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/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new e4cd4a875 refactor: Migrate obs services to context based http client 
(#5682)
e4cd4a875 is described below

commit e4cd4a8754bfdb269df745a367795f8c58b56156
Author: Ziyi Tan <[email protected]>
AuthorDate: Mon Mar 3 21:51:33 2025 +0800

    refactor: Migrate obs services to context based http client (#5682)
---
 core/src/services/obs/backend.rs | 23 +++++++++++++----------
 core/src/services/obs/core.rs    |  5 ++---
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/core/src/services/obs/backend.rs b/core/src/services/obs/backend.rs
index 7ec9a866c..711ed18da 100644
--- a/core/src/services/obs/backend.rs
+++ b/core/src/services/obs/backend.rs
@@ -40,9 +40,12 @@ use crate::*;
 
 impl Configurator for ObsConfig {
     type Builder = ObsBuilder;
+
+    #[allow(deprecated)]
     fn into_builder(self) -> Self::Builder {
         ObsBuilder {
             config: self,
+
             http_client: None,
         }
     }
@@ -53,6 +56,8 @@ impl Configurator for ObsConfig {
 #[derive(Default, Clone)]
 pub struct ObsBuilder {
     config: ObsConfig,
+
+    #[deprecated(since = "0.53.0", note = "Use `Operator::update_http_client` 
instead")]
     http_client: Option<HttpClient>,
 }
 
@@ -132,6 +137,8 @@ impl ObsBuilder {
     ///
     /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed
     /// during minor updates.
+    #[deprecated(since = "0.53.0", note = "Use `Operator::update_http_client` 
instead")]
+    #[allow(deprecated)]
     pub fn http_client(mut self, client: HttpClient) -> Self {
         self.http_client = Some(client);
         self
@@ -184,15 +191,6 @@ impl Builder for ObsBuilder {
         };
         debug!("backend use endpoint {}", &endpoint);
 
-        let client = if let Some(client) = self.http_client {
-            client
-        } else {
-            HttpClient::new().map_err(|err| {
-                err.with_operation("Builder::build")
-                    .with_context("service", Scheme::Obs)
-            })?
-        };
-
         let mut cfg = HuaweicloudObsConfig::default();
         // Load cfg from env first.
         cfg = cfg.from_env();
@@ -287,6 +285,12 @@ impl Builder for ObsBuilder {
                             ..Default::default()
                         });
 
+                    // allow deprecated api here for compatibility
+                    #[allow(deprecated)]
+                    if let Some(client) = self.http_client {
+                        am.update_http_client(|_| client);
+                    }
+
                     am.into()
                 },
                 bucket,
@@ -294,7 +298,6 @@ impl Builder for ObsBuilder {
                 endpoint: format!("{}://{}", &scheme, &endpoint),
                 signer,
                 loader,
-                client,
             }),
         })
     }
diff --git a/core/src/services/obs/core.rs b/core/src/services/obs/core.rs
index bc40f508c..30ba6cab6 100644
--- a/core/src/services/obs/core.rs
+++ b/core/src/services/obs/core.rs
@@ -50,7 +50,6 @@ pub struct ObsCore {
 
     pub signer: HuaweicloudObsSigner,
     pub loader: HuaweicloudObsCredentialLoader,
-    pub client: HttpClient,
 }
 
 impl Debug for ObsCore {
@@ -102,7 +101,7 @@ impl ObsCore {
 
     #[inline]
     pub async fn send(&self, req: Request<Buffer>) -> Result<Response<Buffer>> 
{
-        self.client.send(req).await
+        self.info.http_client().send(req).await
     }
 }
 
@@ -117,7 +116,7 @@ impl ObsCore {
 
         self.sign(&mut req).await?;
 
-        self.client.fetch(req).await
+        self.info.http_client().fetch(req).await
     }
 
     pub fn obs_get_object_request(

Reply via email to