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 4bdc9c633 refactor: Migrate cos services to context based http client
(#5683)
4bdc9c633 is described below
commit 4bdc9c6338407aecf714fc1fc43816af53251e38
Author: Ziyi Tan <[email protected]>
AuthorDate: Mon Mar 3 21:51:55 2025 +0800
refactor: Migrate cos services to context based http client (#5683)
---
core/src/services/cos/backend.rs | 23 +++++++++++++----------
core/src/services/cos/core.rs | 5 ++---
2 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/core/src/services/cos/backend.rs b/core/src/services/cos/backend.rs
index 0e92774c8..7b9ae38a0 100644
--- a/core/src/services/cos/backend.rs
+++ b/core/src/services/cos/backend.rs
@@ -39,9 +39,12 @@ use crate::*;
impl Configurator for CosConfig {
type Builder = CosBuilder;
+
+ #[allow(deprecated)]
fn into_builder(self) -> Self::Builder {
CosBuilder {
config: self,
+
http_client: None,
}
}
@@ -52,6 +55,8 @@ impl Configurator for CosConfig {
#[derive(Default, Clone)]
pub struct CosBuilder {
config: CosConfig,
+
+ #[deprecated(since = "0.53.0", note = "Use `Operator::update_http_client`
instead")]
http_client: Option<HttpClient>,
}
@@ -148,6 +153,8 @@ impl CosBuilder {
///
/// 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
@@ -193,15 +200,6 @@ impl Builder for CosBuilder {
let endpoint = uri.host().unwrap().replace(&format!("//{bucket}."),
"//");
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::Cos)
- })?
- };
-
let mut cfg = TencentCosConfig::default();
if !self.config.disable_config_load {
cfg = cfg.from_env();
@@ -291,6 +289,12 @@ impl Builder for CosBuilder {
..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.clone(),
@@ -298,7 +302,6 @@ impl Builder for CosBuilder {
endpoint: format!("{}://{}.{}", &scheme, &bucket, &endpoint),
signer,
loader: cred_loader,
- client,
}),
})
}
diff --git a/core/src/services/cos/core.rs b/core/src/services/cos/core.rs
index e2c2f269e..ecf1fe532 100644
--- a/core/src/services/cos/core.rs
+++ b/core/src/services/cos/core.rs
@@ -51,7 +51,6 @@ pub struct CosCore {
pub signer: TencentCosSigner,
pub loader: TencentCosCredentialLoader,
- pub client: HttpClient,
}
impl Debug for CosCore {
@@ -106,7 +105,7 @@ impl CosCore {
#[inline]
pub async fn send(&self, req: Request<Buffer>) -> Result<Response<Buffer>>
{
- self.client.send(req).await
+ self.info.http_client().send(req).await
}
}
@@ -121,7 +120,7 @@ impl CosCore {
self.sign(&mut req).await?;
- self.client.fetch(req).await
+ self.info.http_client().fetch(req).await
}
pub fn cos_get_object_request(