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 4fccdf118 refactor: Migrate oss services to context based http client 
(#5681)
4fccdf118 is described below

commit 4fccdf11891fe7cc82f312064a6d406ccce5cec8
Author: Ziyi Tan <[email protected]>
AuthorDate: Mon Mar 3 13:32:33 2025 +0800

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

diff --git a/core/src/services/oss/backend.rs b/core/src/services/oss/backend.rs
index a6f6fd7cb..106ee1025 100644
--- a/core/src/services/oss/backend.rs
+++ b/core/src/services/oss/backend.rs
@@ -41,9 +41,12 @@ const DEFAULT_BATCH_MAX_OPERATIONS: usize = 1000;
 
 impl Configurator for OssConfig {
     type Builder = OssBuilder;
+
+    #[allow(deprecated)]
     fn into_builder(self) -> Self::Builder {
         OssBuilder {
             config: self,
+
             http_client: None,
         }
     }
@@ -54,6 +57,8 @@ impl Configurator for OssConfig {
 #[derive(Default)]
 pub struct OssBuilder {
     config: OssConfig,
+
+    #[deprecated(since = "0.53.0", note = "Use `Operator::update_http_client` 
instead")]
     http_client: Option<HttpClient>,
 }
 
@@ -151,6 +156,8 @@ impl OssBuilder {
     ///
     /// 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
@@ -389,15 +396,6 @@ impl Builder for OssBuilder {
             cfg.sts_endpoint = Some(v);
         }
 
-        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::Oss)
-            })?
-        };
-
         let loader = AliyunLoader::new(GLOBAL_REQWEST_CLIENT.clone(), cfg);
 
         let signer = AliyunOssSigner::new(bucket);
@@ -490,6 +488,12 @@ impl Builder for OssBuilder {
                             ..Default::default()
                         });
 
+                    // allow deprecated api here for compatibility
+                    #[allow(deprecated)]
+                    if let Some(client) = self.http_client {
+                        am.update_http_client(|_| client);
+                    }
+
                     am.into()
                 },
                 root,
@@ -500,7 +504,6 @@ impl Builder for OssBuilder {
                 allow_anonymous: self.config.allow_anonymous,
                 signer,
                 loader,
-                client,
                 server_side_encryption,
                 server_side_encryption_key_id,
             }),
diff --git a/core/src/services/oss/core.rs b/core/src/services/oss/core.rs
index 521ff1d89..2f9116b86 100644
--- a/core/src/services/oss/core.rs
+++ b/core/src/services/oss/core.rs
@@ -77,7 +77,6 @@ pub struct OssCore {
     pub server_side_encryption: Option<HeaderValue>,
     pub server_side_encryption_key_id: Option<HeaderValue>,
 
-    pub client: HttpClient,
     pub loader: AliyunLoader,
     pub signer: AliyunOssSigner,
 }
@@ -140,7 +139,7 @@ impl OssCore {
 
     #[inline]
     pub async fn send(&self, req: Request<Buffer>) -> Result<Response<Buffer>> 
{
-        self.client.send(req).await
+        self.info.http_client().send(req).await
     }
 
     /// Set sse headers
@@ -475,7 +474,7 @@ impl OssCore {
     pub async fn oss_get_object(&self, path: &str, args: &OpRead) -> 
Result<Response<HttpBody>> {
         let mut req = self.oss_get_object_request(path, false, args)?;
         self.sign(&mut req).await?;
-        self.client.fetch(req).await
+        self.info.http_client().fetch(req).await
     }
 
     pub async fn oss_head_object(&self, path: &str, args: &OpStat) -> 
Result<Response<Buffer>> {

Reply via email to