Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ changes go in their respective binding's NEXT_CHANGELOG.

- Add an opt-in `release-with-debuginfo` Cargo profile and cross-platform
symbol smoke checks for statically linked native consumers.
- Create SQL Exec API sessions in FAST mode and exchange the maximum observed session version.
- Add a C ABI setter for the maximum idle HTTP connections retained per host.
- C ABI: `kernel_statement_set_query_tags()` attaches per-statement query tags
(serialized `key:value` wire form) to a statement's execution, letting C ABI
Expand Down
19 changes: 12 additions & 7 deletions src/client/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::auth::AuthProvider;
use crate::client::retry::{
calculate_backoff, RequestCategory, RequestType, RetryConfig, RetryStrategy,
};
use crate::client::DIRECT_ROUTING_HEADER;
use crate::kernel_error::{Error, Result};
use crate::klog::{debug, warn};
use crate::types::sea::ServiceError;
Expand Down Expand Up @@ -852,11 +853,9 @@ impl DatabricksHttpClient {
// kernel's own auth / routing headers (set last, below) take
// precedence — matching the Thrift connector, where
// `auth_provider.add_headers` runs after the custom-header
// dict. We SKIP any custom header named `Authorization` or
// `x-databricks-org-id` (case-insensitive) so a stray caller
// header can't sit alongside the kernel's (reqwest appends
// same-named headers rather than replacing, which for those
// two would send a duplicate and could confuse the server).
// dict. Kernel-managed authentication and routing headers are
// skipped here so caller values cannot coexist with the values
// selected by the kernel.
// `User-Agent` is NOT in this map — it was folded into the
// client's effective UA in `new()` (a caller UA replaces the
// base, which then becomes reqwest's default UA header).
Expand All @@ -869,7 +868,10 @@ impl DatabricksHttpClient {
// transport, IdP calls included.
for (name, value) in &self.config.custom_headers {
let lname = name.to_ascii_lowercase();
if lname == "authorization" || lname == "x-databricks-org-id" {
if lname == "authorization"
|| lname == "x-databricks-org-id"
|| lname == DIRECT_ROUTING_HEADER
{
warn!(
header = %name,
"ignoring caller-supplied custom header; this name is \
Expand Down Expand Up @@ -1114,7 +1116,7 @@ mod tests {
}

#[tokio::test]
async fn test_custom_headers_applied_with_auth_winning() {
async fn test_custom_headers_applied_with_kernel_headers_winning() {
use wiremock::matchers::{header, method, path};
use wiremock::{Mock, MockServer, ResponseTemplate};

Expand Down Expand Up @@ -1151,6 +1153,7 @@ mod tests {
"Authorization".to_string(),
"Bearer caller-bogus".to_string(),
),
(DIRECT_ROUTING_HEADER.to_string(), "true".to_string()),
],
..HttpClientConfig::default()
};
Expand All @@ -1167,6 +1170,8 @@ mod tests {
.await
.expect("request should succeed against the mock");
assert_eq!(resp.status().as_u16(), 200);
let requests = server.received_requests().await.unwrap();
assert!(requests[0].headers.get(DIRECT_ROUTING_HEADER).is_none());
// If the matchers above didn't all match, wiremock returns the
// default 404 and the status assert fails — so a 200 confirms
// custom header + caller UA present AND auth = real-token.
Expand Down
4 changes: 3 additions & 1 deletion src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub mod retry;
pub mod sea;
pub(crate) mod transport;

pub(crate) const DIRECT_ROUTING_HEADER: &str = "x-databricks-direct-routing";

// Public surface — kept stable for advanced wrappers that tune HTTP.
pub use http::{DatabricksHttpClient, HttpClientConfig, ProxyConfig};
pub use retry::{
Expand All @@ -46,5 +48,5 @@ pub use retry::{
pub(crate) use sea::SeaRestTransport;
pub(crate) use transport::{
ChunkLinkFetchResult, DirectOutcome, ExecuteResponse, ExecuteResult, ExecuteResultData,
InlineChunkFetchResult, SessionInfo, Transport, TransportConfig,
InlineChunkFetchResult, SessionAttribution, SessionInfo, Transport, TransportConfig,
};
Loading
Loading