Skip to content

Commit f0295f8

Browse files
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]>
1 parent 755a0d2 commit f0295f8

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

crates/catalog/rest/src/client.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,15 @@ impl Debug for HttpClient {
5757
impl HttpClient {
5858
/// Create a new http client.
5959
pub fn new(cfg: &RestCatalogConfig) -> Result<Self> {
60+
let extra_headers = cfg.extra_headers()?;
6061
Ok(HttpClient {
61-
client: Client::new(),
62+
client: Client::builder()
63+
.default_headers(extra_headers.clone())
64+
.build()?,
6265
token: Mutex::new(cfg.token()),
6366
token_endpoint: cfg.get_token_endpoint(),
6467
credential: cfg.credential(),
65-
extra_headers: cfg.extra_headers()?,
68+
extra_headers,
6669
extra_oauth_params: cfg.extra_oauth_params(),
6770
})
6871
}
@@ -72,8 +75,14 @@ impl HttpClient {
7275
/// If cfg carries new value, we will use cfg instead.
7376
/// Otherwise, we will keep the old value.
7477
pub fn update_with(self, cfg: &RestCatalogConfig) -> Result<Self> {
78+
let extra_headers = (!cfg.extra_headers()?.is_empty())
79+
.then(|| cfg.extra_headers())
80+
.transpose()?
81+
.unwrap_or(self.extra_headers);
7582
Ok(HttpClient {
76-
client: self.client,
83+
client: Client::builder()
84+
.default_headers(extra_headers.clone())
85+
.build()?,
7786
token: Mutex::new(
7887
cfg.token()
7988
.or_else(|| self.token.into_inner().ok().flatten()),
@@ -82,10 +91,7 @@ impl HttpClient {
8291
.then(|| cfg.get_token_endpoint())
8392
.unwrap_or(self.token_endpoint),
8493
credential: cfg.credential().or(self.credential),
85-
extra_headers: (!cfg.extra_headers()?.is_empty())
86-
.then(|| cfg.extra_headers())
87-
.transpose()?
88-
.unwrap_or(self.extra_headers),
94+
extra_headers,
8995
extra_oauth_params: (!cfg.extra_oauth_params().is_empty())
9096
.then(|| cfg.extra_oauth_params())
9197
.unwrap_or(self.extra_oauth_params),

0 commit comments

Comments
 (0)