From 411568b72cc0dbd4134142638fc3eab2009481dd Mon Sep 17 00:00:00 2001 From: Jack Ye Date: Wed, 24 Jun 2026 13:25:59 -0700 Subject: [PATCH] fix(remote): omit empty api key header (#3573) ## Summary Skip inserting the x-api-key header when the configured API key is empty. This lets bearer-token or other dynamic-header authentication avoid sending an empty static API key header alongside the real auth header. --- rust/lancedb/src/remote/client.rs | 41 ++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/rust/lancedb/src/remote/client.rs b/rust/lancedb/src/remote/client.rs index 6a44f7f1c..d4a65fe15 100644 --- a/rust/lancedb/src/remote/client.rs +++ b/rust/lancedb/src/remote/client.rs @@ -459,12 +459,14 @@ impl RestfulLanceDbClient { config: &ClientConfig, ) -> Result { let mut headers = HeaderMap::new(); - headers.insert( - HeaderName::from_static("x-api-key"), - HeaderValue::from_str(api_key).map_err(|_| Error::InvalidInput { - message: "non-ascii api key provided".to_string(), - })?, - ); + if !api_key.is_empty() { + headers.insert( + HeaderName::from_static("x-api-key"), + HeaderValue::from_str(api_key).map_err(|_| Error::InvalidInput { + message: "non-ascii api key provided".to_string(), + })?, + ); + } if region == "local" { let host = format!("{}.local.api.lancedb.com", db_name); headers.insert( @@ -1005,6 +1007,33 @@ mod tests { assert!(!config_tls.assert_hostname); } + #[test] + fn test_default_headers_skip_empty_api_key() { + let headers = RestfulLanceDbClient::::default_headers( + "", + "us-east-1", + "db-name", + false, + &RemoteOptions::default(), + None, + &ClientConfig::default(), + ) + .unwrap(); + assert!(!headers.contains_key("x-api-key")); + + let headers = RestfulLanceDbClient::::default_headers( + "api-key", + "us-east-1", + "db-name", + false, + &RemoteOptions::default(), + None, + &ClientConfig::default(), + ) + .unwrap(); + assert_eq!(headers.get("x-api-key").unwrap(), "api-key"); + } + // Test implementation of HeaderProvider #[derive(Debug, Clone)] struct TestHeaderProvider {