Skip to content
Merged
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
11 changes: 5 additions & 6 deletions napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,19 +490,18 @@ export interface ConnectionOptions {
* An **ordered list** of `(name, value)` pairs, mirroring the kernel
* core's `Vec<(String, String)>` and the pyo3 binding's
* `http_headers` — order is preserved and duplicate names are
* allowed (the kernel emits each entry, and for `User-Agent` folds
* the **last** one into its base UA).
* allowed (the kernel emits each entry, and uses the **last**
* `User-Agent` as its effective UA).
*
* Three names are handled specially by the kernel:
* - `Authorization` / `x-databricks-org-id` are **reserved** — a
* caller entry for either is silently dropped (skip-and-warn) so
* auth and multi-tenant routing can't be hijacked by a custom
* header. (The NodeJS driver also drops these before they cross
* the FFI, matching the Python connector's double-wall.)
* - `User-Agent` is **appended** to the kernel base UA (rather than
* replacing it), preserving the `DatabricksJDBCDriverOSS/...`
* token the SEA server keys on while still surfacing the caller's
* identity. The NodeJS driver folds its `userAgentEntry` into a
* - `User-Agent` **replaces** the `DatabricksSQLKernel/...` base.
* Its leading prefix must therefore be allow-listed by the SEA
* server. The NodeJS driver folds its `userAgentEntry` into a
* `User-Agent` entry here.
*/
customHeaders?: Array<HeaderEntry>
Expand Down
11 changes: 5 additions & 6 deletions napi/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,19 +362,18 @@ pub struct ConnectionOptions {
/// An **ordered list** of `(name, value)` pairs, mirroring the kernel
/// core's `Vec<(String, String)>` and the pyo3 binding's
/// `http_headers` — order is preserved and duplicate names are
/// allowed (the kernel emits each entry, and for `User-Agent` folds
/// the **last** one into its base UA).
/// allowed (the kernel emits each entry, and uses the **last**
/// `User-Agent` as its effective UA).
///
/// Three names are handled specially by the kernel:
/// - `Authorization` / `x-databricks-org-id` are **reserved** — a
/// caller entry for either is silently dropped (skip-and-warn) so
/// auth and multi-tenant routing can't be hijacked by a custom
/// header. (The NodeJS driver also drops these before they cross
/// the FFI, matching the Python connector's double-wall.)
/// - `User-Agent` is **appended** to the kernel base UA (rather than
/// replacing it), preserving the `DatabricksJDBCDriverOSS/...`
/// token the SEA server keys on while still surfacing the caller's
/// identity. The NodeJS driver folds its `userAgentEntry` into a
/// - `User-Agent` **replaces** the `DatabricksSQLKernel/...` base.
/// Its leading prefix must therefore be allow-listed by the SEA
/// server. The NodeJS driver folds its `userAgentEntry` into a
/// `User-Agent` entry here.
pub custom_headers: Option<Vec<HeaderEntry>>,

Expand Down
31 changes: 17 additions & 14 deletions src/client/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,10 @@ impl Default for HttpClientConfig {
connect_timeout: Duration::from_secs(30),
read_timeout: Duration::from_secs(60),
max_connections_per_host: 100,
// TODO: Update user agent to properly identify as Rust ADBC driver.
// Currently using JDBC user agent to enable INLINE_OR_EXTERNAL_LINKS disposition
// which returns all chunk links in a single response, enabling true parallel downloads.
// See: https://github.com/databricks-eng/universe/pull/909153
user_agent: format!("DatabricksJDBCDriverOSS/{}", env!("CARGO_PKG_VERSION")),
// This kernel-specific prefix is allow-listed by
// databricks.sqlexecapi.known_driver_prefixes, which enables
// INLINE_OR_EXTERNAL_LINKS while preserving accurate attribution.
user_agent: format!("DatabricksSQLKernel/{}", env!("CARGO_PKG_VERSION")),
proxy: ProxyConfig::default(),
tls: TlsConfig::default(),
org_id: None,
Expand Down Expand Up @@ -402,7 +401,7 @@ impl DatabricksHttpClient {
// A caller `User-Agent` **replaces** the kernel's base UA
// entirely: the effective UA becomes the caller string verbatim
// (e.g. the connector's composed `PyDatabricksSqlConnector/x
// (entry)`), with no `DatabricksJDBCDriverOSS/...` prefix. This is
// (entry)`), with no `DatabricksSQLKernel/...` prefix. This is
// intentional — it gives the SEA server an accurate driver
// identity for query-source attribution (the appended-prefix shape
// matched none of the gateway's `parseUserAgent` patterns and was
Expand All @@ -416,7 +415,7 @@ impl DatabricksHttpClient {
// of that flag; a UA whose prefix is not allow-listed is rejected
// with HTTP 400 "not a supported disposition" / redirected to
// Thrift. `PyDatabricksSqlConnector` is allow-listed for this
// reason. The base UA below remains `DatabricksJDBCDriverOSS/...`
// reason. The base UA below remains `DatabricksSQLKernel/...`
// so requests with NO caller UA still pass the gate.
//
// Last UA wins if a caller somehow set several.
Expand Down Expand Up @@ -1053,6 +1052,10 @@ mod tests {
assert_eq!(config.connect_timeout, Duration::from_secs(30));
assert_eq!(config.read_timeout, Duration::from_secs(60));
assert_eq!(config.max_connections_per_host, 100);
assert_eq!(
config.user_agent,
format!("DatabricksSQLKernel/{}", env!("CARGO_PKG_VERSION"))
);
}

#[tokio::test]
Expand Down Expand Up @@ -1161,7 +1164,7 @@ mod tests {
// from the custom-header list (so it isn't re-applied per request;
// it becomes reqwest's default UA instead).
let config = HttpClientConfig {
user_agent: "DatabricksJDBCDriverOSS/9.9".to_string(),
user_agent: "DatabricksSQLKernel/9.9".to_string(),
custom_headers: vec![
("x-keep".to_string(), "v".to_string()),
(
Expand Down Expand Up @@ -1196,24 +1199,24 @@ mod tests {
fn test_empty_caller_user_agent_keeps_base() {
// A whitespace-only caller UA is ignored — the base UA stays so
// the request still carries an identity (and the
// disposition-gating prefix when the base is the JDBC token).
// disposition-gating prefix when the base is allow-listed).
let config = HttpClientConfig {
user_agent: "DatabricksJDBCDriverOSS/9.9".to_string(),
user_agent: "DatabricksSQLKernel/9.9".to_string(),
custom_headers: vec![("User-Agent".to_string(), " ".to_string())],
..HttpClientConfig::default()
};
let client = DatabricksHttpClient::new(config, default_retry_configs()).unwrap();
assert_eq!(client.config().user_agent, "DatabricksJDBCDriverOSS/9.9");
assert_eq!(client.config().user_agent, "DatabricksSQLKernel/9.9");
}

#[test]
fn test_no_caller_user_agent_keeps_base() {
let config = HttpClientConfig {
user_agent: "DatabricksJDBCDriverOSS/9.9".to_string(),
user_agent: "DatabricksSQLKernel/9.9".to_string(),
..HttpClientConfig::default()
};
let client = DatabricksHttpClient::new(config, default_retry_configs()).unwrap();
assert_eq!(client.config().user_agent, "DatabricksJDBCDriverOSS/9.9");
assert_eq!(client.config().user_agent, "DatabricksSQLKernel/9.9");
}

#[test]
Expand All @@ -1223,7 +1226,7 @@ mod tests {
let mut ua = "x".repeat(1023);
ua.push('é'); // 2 bytes straddling the 1024-byte limit
let config = HttpClientConfig {
user_agent: "DatabricksJDBCDriverOSS/9.9".to_string(),
user_agent: "DatabricksSQLKernel/9.9".to_string(),
custom_headers: vec![("User-Agent".to_string(), ua)],
..HttpClientConfig::default()
};
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ pub struct HttpConfig {
/// removed from this list. This gives the SEA server an accurate
/// driver identity for query-source attribution (e.g. the connector's
/// `PyDatabricksSqlConnector/x (entry)`), instead of the
/// `DatabricksJDBCDriverOSS/...` base.
/// `DatabricksSQLKernel/...` base.
///
/// PRECONDITION: the caller UA's leading prefix MUST be in the
/// gateway's `databricks.sqlexecapi.known_driver_prefixes` SAFE flag.
Expand All @@ -808,7 +808,7 @@ pub struct HttpConfig {
/// `startsWith` prefix match of that flag; a non-allow-listed prefix
/// is rejected (HTTP 400 / Thrift redirect). `PyDatabricksSqlConnector`
/// is allow-listed for this reason. When NO caller `User-Agent` is
/// supplied, the base UA stays `DatabricksJDBCDriverOSS/...` so the
/// supplied, the base UA stays `DatabricksSQLKernel/...` so the
/// gate still passes.
///
/// **All other headers are sent as supplied.** A `Vec` (not a map)
Expand Down
Loading