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 1dfdad43c refactor: Migrate b2 service to context based http client (#5843) 1dfdad43c is described below commit 1dfdad43c1399722b33834bcf50aa1b04c0cb0a4 Author: miro <h...@miro.im> AuthorDate: Fri Mar 21 17:37:11 2025 +0800 refactor: Migrate b2 service to context based http client (#5843) --- core/src/services/b2/backend.rs | 21 +++++++++++---------- core/src/services/b2/core.rs | 8 +++----- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/core/src/services/b2/backend.rs b/core/src/services/b2/backend.rs index e095915d8..7504188e5 100644 --- a/core/src/services/b2/backend.rs +++ b/core/src/services/b2/backend.rs @@ -42,6 +42,8 @@ use crate::*; impl Configurator for B2Config { type Builder = B2Builder; + + #[allow(deprecated)] fn into_builder(self) -> Self::Builder { B2Builder { config: self, @@ -56,6 +58,7 @@ impl Configurator for B2Config { pub struct B2Builder { config: B2Config, + #[deprecated(since = "0.53.0", note = "Use `Operator::update_http_client` instead")] http_client: Option<HttpClient>, } @@ -126,6 +129,8 @@ impl B2Builder { /// /// 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 @@ -179,15 +184,6 @@ impl Builder for B2Builder { ), }?; - 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::B2) - })? - }; - let signer = B2Signer { application_key_id, application_key, @@ -249,6 +245,12 @@ impl Builder for B2Builder { ..Default::default() }); + // allow deprecated api here for compatibility + #[allow(deprecated)] + if let Some(client) = self.http_client { + am.update_http_client(|_| client); + } + am.into() }, signer: Arc::new(RwLock::new(signer)), @@ -256,7 +258,6 @@ impl Builder for B2Builder { bucket: self.config.bucket.clone(), bucket_id: self.config.bucket_id.clone(), - client, }), }) } diff --git a/core/src/services/b2/core.rs b/core/src/services/b2/core.rs index 2c2733b0e..e282ff497 100644 --- a/core/src/services/b2/core.rs +++ b/core/src/services/b2/core.rs @@ -56,8 +56,6 @@ pub struct B2Core { pub bucket: String, /// The bucket id of this backend. pub bucket_id: String, - - pub client: HttpClient, } impl Debug for B2Core { @@ -73,7 +71,7 @@ impl Debug for B2Core { impl B2Core { #[inline] pub async fn send(&self, req: Request<Buffer>) -> Result<Response<Buffer>> { - self.client.send(req).await + self.info.http_client().send(req).await } /// [b2_authorize_account](https://www.backblaze.com/apidocs/b2-authorize-account) @@ -102,7 +100,7 @@ impl B2Core { .body(Buffer::new()) .map_err(new_request_build_error)?; - let resp = self.client.send(req).await?; + let resp = self.info.http_client().send(req).await?; let status = resp.status(); match status { @@ -158,7 +156,7 @@ impl B2Core { let req = req.body(Buffer::new()).map_err(new_request_build_error)?; - self.client.fetch(req).await + self.info.http_client().fetch(req).await } pub(super) async fn get_upload_url(&self) -> Result<GetUploadUrlResponse> {