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
2 changes: 2 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ changes go in their respective binding's NEXT_CHANGELOG.

### Added

- Negotiate real-time direct routing during session creation and attach the returned session ID to
session-owned follow-up requests.
### Changed

### Updated
Expand Down
31 changes: 31 additions & 0 deletions src/client/headers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2026 Databricks, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

pub(super) const DBSQL_SESSION_ID_HEADER: &str = "x-databricks-dbsql-session-id";
pub(super) const REALTIME_DIRECT_ROUTING_HEADER: &str = "x-databricks-realtime-direct-routing";
pub(super) const REALTIME_SESSION_HEADER: &str = "x-databricks-realtime-session";

const KERNEL_MANAGED_HEADERS: &[&str] = &[
"authorization",
"x-databricks-org-id",
DBSQL_SESSION_ID_HEADER,
REALTIME_DIRECT_ROUTING_HEADER,
REALTIME_SESSION_HEADER,
];

pub(super) fn is_kernel_managed_header(name: &str) -> bool {
KERNEL_MANAGED_HEADERS
.iter()
.any(|managed| name.eq_ignore_ascii_case(managed))
}
33 changes: 25 additions & 8 deletions src/client/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
//! - Configurable timeouts

use crate::auth::AuthProvider;
use crate::client::headers::is_kernel_managed_header;
use crate::client::retry::{
calculate_backoff, RequestCategory, RequestType, RetryConfig, RetryStrategy,
};
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 session-routing
// headers are skipped 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 @@ -868,8 +867,7 @@ impl DatabricksHttpClient {
// `setCustomHeaders` applies to every request on the
// 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 is_kernel_managed_header(name) {
warn!(
header = %name,
"ignoring caller-supplied custom header; this name is \
Expand Down Expand Up @@ -1054,6 +1052,9 @@ impl DatabricksHttpClient {
mod tests {
use super::*;
use crate::auth::PersonalAccessToken;
use crate::client::headers::{
DBSQL_SESSION_ID_HEADER, REALTIME_DIRECT_ROUTING_HEADER, REALTIME_SESSION_HEADER,
};
use crate::client::retry::build_retry_configs;

fn default_retry_configs() -> HashMap<RequestCategory, RetryConfig> {
Expand Down Expand Up @@ -1114,7 +1115,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 +1152,15 @@ mod tests {
"Authorization".to_string(),
"Bearer caller-bogus".to_string(),
),
(
REALTIME_DIRECT_ROUTING_HEADER.to_string(),
"false".to_string(),
),
(REALTIME_SESSION_HEADER.to_string(), "true".to_string()),
(
DBSQL_SESSION_ID_HEADER.to_string(),
"caller-session".to_string(),
),
],
..HttpClientConfig::default()
};
Expand All @@ -1167,6 +1177,13 @@ 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(REALTIME_DIRECT_ROUTING_HEADER)
.is_none());
assert!(requests[0].headers.get(REALTIME_SESSION_HEADER).is_none());
assert!(requests[0].headers.get(DBSQL_SESSION_ID_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
1 change: 1 addition & 0 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
//! [`transport`]: self::transport
//! [`sea`]: self::sea

mod headers;
pub mod http;
pub mod retry;
pub mod sea;
Expand Down
Loading
Loading