Skip to content

Commit f16f1a9

Browse files
author
Hongyi Wang
committed
Avoid overwriting default headers
1 parent 0876420 commit f16f1a9

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

crates/catalog/rest/src/catalog.rs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,25 @@ impl RestCatalogConfig {
131131

132132
for (key, value) in self.props.iter() {
133133
if let Some(stripped_key) = key.strip_prefix("header.") {
134-
headers.insert(
135-
HeaderName::from_str(stripped_key).map_err(|e| {
136-
Error::new(
137-
ErrorKind::DataInvalid,
138-
format!("Invalid header name: {stripped_key}!"),
139-
)
140-
.with_source(e)
141-
})?,
142-
HeaderValue::from_str(value).map_err(|e| {
143-
Error::new(
144-
ErrorKind::DataInvalid,
145-
format!("Invalid header value: {value}!"),
146-
)
147-
.with_source(e)
148-
})?,
149-
);
134+
// Avoid overwriting default headers
135+
if !headers.contains_key(stripped_key) {
136+
headers.insert(
137+
HeaderName::from_str(stripped_key).map_err(|e| {
138+
Error::new(
139+
ErrorKind::DataInvalid,
140+
format!("Invalid header name: {stripped_key}!"),
141+
)
142+
.with_source(e)
143+
})?,
144+
HeaderValue::from_str(value).map_err(|e| {
145+
Error::new(
146+
ErrorKind::DataInvalid,
147+
format!("Invalid header value: {value}!"),
148+
)
149+
.with_source(e)
150+
})?,
151+
);
152+
}
150153
}
151154
}
152155
Ok(headers)
@@ -1020,6 +1023,10 @@ mod tests {
10201023
"header.content-type".to_string(),
10211024
"application/yaml".to_string(),
10221025
);
1026+
props.insert(
1027+
"header.customized-header".to_string(),
1028+
"some/value".to_string(),
1029+
);
10231030

10241031
let config = RestCatalogConfig::builder()
10251032
.uri(server.url())
@@ -1030,7 +1037,7 @@ mod tests {
10301037
let expected_headers = HeaderMap::from_iter([
10311038
(
10321039
header::CONTENT_TYPE,
1033-
HeaderValue::from_static("application/yaml"),
1040+
HeaderValue::from_static("application/json"),
10341041
),
10351042
(
10361043
HeaderName::from_static("x-client-version"),
@@ -1040,6 +1047,10 @@ mod tests {
10401047
header::USER_AGENT,
10411048
HeaderValue::from_str(&format!("iceberg-rs/{}", CARGO_PKG_VERSION)).unwrap(),
10421049
),
1050+
(
1051+
HeaderName::from_static("customized-header"),
1052+
HeaderValue::from_static("some/value"),
1053+
),
10431054
]);
10441055
assert_eq!(headers, expected_headers);
10451056
}

0 commit comments

Comments
 (0)