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 dba933bf4 refactor: Migrate s3 services to context based http client 
(#5676)
dba933bf4 is described below

commit dba933bf4781096052bedcbbb24574b66b546885
Author: Xuanwo <[email protected]>
AuthorDate: Sat Mar 1 22:21:51 2025 +0800

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

diff --git a/core/src/services/s3/backend.rs b/core/src/services/s3/backend.rs
index 995144ef2..93cfd1aa0 100644
--- a/core/src/services/s3/backend.rs
+++ b/core/src/services/s3/backend.rs
@@ -67,10 +67,13 @@ const DEFAULT_BATCH_MAX_OPERATIONS: usize = 1000;
 
 impl Configurator for S3Config {
     type Builder = S3Builder;
+
+    #[allow(deprecated)]
     fn into_builder(self) -> Self::Builder {
         S3Builder {
             config: self,
             customized_credential_load: None,
+
             http_client: None,
         }
     }
@@ -85,6 +88,8 @@ pub struct S3Builder {
     config: S3Config,
 
     customized_credential_load: Option<Box<dyn AwsCredentialLoad>>,
+
+    #[deprecated(since = "0.53.0", note = "Use `Operator::update_http_client` 
instead")]
     http_client: Option<HttpClient>,
 }
 
@@ -454,6 +459,8 @@ impl S3Builder {
     ///
     /// 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
@@ -810,15 +817,6 @@ impl Builder for S3Builder {
             cfg.session_token = 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::S3)
-            })?
-        };
-
         let mut loader: Option<Box<dyn AwsCredentialLoad>> = None;
         // If customized_credential_load is set, we will use it.
         if let Some(v) = self.customized_credential_load {
@@ -981,6 +979,12 @@ impl Builder for S3Builder {
                             ..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: bucket.to_string(),
@@ -996,7 +1000,6 @@ impl Builder for S3Builder {
                 signer,
                 loader,
                 credential_loaded: AtomicBool::new(false),
-                client,
                 checksum_algorithm,
             }),
         })
diff --git a/core/src/services/s3/core.rs b/core/src/services/s3/core.rs
index d4375b520..173a33d50 100644
--- a/core/src/services/s3/core.rs
+++ b/core/src/services/s3/core.rs
@@ -101,7 +101,6 @@ pub struct S3Core {
     pub signer: AwsV4Signer,
     pub loader: Box<dyn AwsCredentialLoad>,
     pub credential_loaded: AtomicBool,
-    pub client: HttpClient,
     pub checksum_algorithm: Option<ChecksumAlgorithm>,
 }
 
@@ -198,7 +197,7 @@ impl S3Core {
 
     #[inline]
     pub async fn send(&self, req: Request<Buffer>) -> Result<Response<Buffer>> 
{
-        self.client.send(req).await
+        self.info.http_client().send(req).await
     }
 
     /// # Note
@@ -503,7 +502,7 @@ impl S3Core {
 
         self.sign(&mut req).await?;
 
-        self.client.fetch(req).await
+        self.info.http_client().fetch(req).await
     }
 
     pub fn s3_put_object_request(

Reply via email to