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/iceberg-rust.git
The following commit(s) were added to refs/heads/main by this push:
new f0295f80 fix: fix http custom headers for rest catalog (#1010)
f0295f80 is described below
commit f0295f80a1fa5ae0d9be17fac5e4a973dcfde638
Author: Dylan <[email protected]>
AuthorDate: Wed Mar 19 11:16:41 2025 +0800
fix: fix http custom headers for rest catalog (#1010)
- Add `extra_headers` to the http client. Previously, we didn't use
`extra_headers`.
~~- Support multiple values for customer headers. Because we use a
HashMap as RestCatalog properties, we can't specify multiple values for
a single HTTP header directly. This PR parses and extracts multiple
values from the properties for each header.~~
---------
Co-authored-by: Renjie Liu <[email protected]>
---
crates/catalog/rest/src/client.rs | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/crates/catalog/rest/src/client.rs
b/crates/catalog/rest/src/client.rs
index dde75276..39b9cf2f 100644
--- a/crates/catalog/rest/src/client.rs
+++ b/crates/catalog/rest/src/client.rs
@@ -57,12 +57,15 @@ impl Debug for HttpClient {
impl HttpClient {
/// Create a new http client.
pub fn new(cfg: &RestCatalogConfig) -> Result<Self> {
+ let extra_headers = cfg.extra_headers()?;
Ok(HttpClient {
- client: Client::new(),
+ client: Client::builder()
+ .default_headers(extra_headers.clone())
+ .build()?,
token: Mutex::new(cfg.token()),
token_endpoint: cfg.get_token_endpoint(),
credential: cfg.credential(),
- extra_headers: cfg.extra_headers()?,
+ extra_headers,
extra_oauth_params: cfg.extra_oauth_params(),
})
}
@@ -72,8 +75,14 @@ impl HttpClient {
/// If cfg carries new value, we will use cfg instead.
/// Otherwise, we will keep the old value.
pub fn update_with(self, cfg: &RestCatalogConfig) -> Result<Self> {
+ let extra_headers = (!cfg.extra_headers()?.is_empty())
+ .then(|| cfg.extra_headers())
+ .transpose()?
+ .unwrap_or(self.extra_headers);
Ok(HttpClient {
- client: self.client,
+ client: Client::builder()
+ .default_headers(extra_headers.clone())
+ .build()?,
token: Mutex::new(
cfg.token()
.or_else(|| self.token.into_inner().ok().flatten()),
@@ -82,10 +91,7 @@ impl HttpClient {
.then(|| cfg.get_token_endpoint())
.unwrap_or(self.token_endpoint),
credential: cfg.credential().or(self.credential),
- extra_headers: (!cfg.extra_headers()?.is_empty())
- .then(|| cfg.extra_headers())
- .transpose()?
- .unwrap_or(self.extra_headers),
+ extra_headers,
extra_oauth_params: (!cfg.extra_oauth_params().is_empty())
.then(|| cfg.extra_oauth_params())
.unwrap_or(self.extra_oauth_params),