You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2025/03/16 07:05:36 UTC
(opendal) branch main updated: refactor(gcs): Migrate to context based http client (#5778)
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 67a3549cd refactor(gcs): Migrate to context based http client (#5778)
67a3549cd is described below
commit 67a3549cda8020b447492f52b8ebee46ad68ca2a
Author: Yu Lei <le...@outlook.com>
AuthorDate: Sun Mar 16 15:05:31 2025 +0800
refactor(gcs): Migrate to context based http client (#5778)
---
core/src/services/gcs/backend.rs | 22 ++++++++++++----------
core/src/services/gcs/core.rs | 5 ++---
2 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/core/src/services/gcs/backend.rs b/core/src/services/gcs/backend.rs
index d2b833463..efec94e25 100644
--- a/core/src/services/gcs/backend.rs
+++ b/core/src/services/gcs/backend.rs
@@ -47,6 +47,8 @@ const DEFAULT_GCS_SCOPE: &str = "https://www.googleapis.com/auth/devstorage.read
impl Configurator for GcsConfig {
type Builder = GcsBuilder;
+
+ #[allow(deprecated)]
fn into_builder(self) -> Self::Builder {
GcsBuilder {
config: self,
@@ -62,6 +64,7 @@ impl Configurator for GcsConfig {
pub struct GcsBuilder {
config: GcsConfig,
+ #[deprecated(since = "0.53.0", note = "Use `Operator::update_http_client` instead")]
http_client: Option<HttpClient>,
customized_token_loader: Option<Box<dyn GoogleTokenLoad>>,
}
@@ -163,6 +166,8 @@ impl GcsBuilder {
///
/// 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
@@ -254,15 +259,6 @@ impl Builder for GcsBuilder {
// TODO: server side encryption
- 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::Gcs)
- })?
- };
-
let endpoint = self
.config
.endpoint
@@ -382,12 +378,18 @@ impl Builder for GcsBuilder {
..Default::default()
});
+
+ // allow deprecated api here for compatibility
+ #[allow(deprecated)]
+ if let Some(client) = self.http_client {
+ am.update_http_client(|_| client);
+ }
+
am.into()
},
endpoint,
bucket: bucket.to_string(),
root,
- client,
signer,
token_loader,
token: self.config.token,
diff --git a/core/src/services/gcs/core.rs b/core/src/services/gcs/core.rs
index 1191edd84..8a6fd5475 100644
--- a/core/src/services/gcs/core.rs
+++ b/core/src/services/gcs/core.rs
@@ -61,7 +61,6 @@ pub struct GcsCore {
pub bucket: String,
pub root: String,
- pub client: HttpClient,
pub signer: GoogleSigner,
pub token_loader: GoogleTokenLoader,
pub token: Option<String>,
@@ -174,7 +173,7 @@ impl GcsCore {
#[inline]
pub async fn send(&self, req: Request<Buffer>) -> Result<Response<Buffer>> {
- self.client.send(req).await
+ self.info.http_client().send(req).await
}
}
@@ -254,7 +253,7 @@ impl GcsCore {
let mut req = self.gcs_get_object_request(path, range, args)?;
self.sign(&mut req).await?;
- self.client.fetch(req).await
+ self.info.http_client().fetch(req).await
}
pub fn gcs_insert_object_request(