Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions src/qdrant_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,27 @@ impl Qdrant {
Ok(result)
}

/// Create a lightweight clone of this client with an additional header.
///
/// The returned client shares the same connection pool but sends
/// the extra header with every request. Useful for per-request
/// tracing IDs or other contextual metadata.
///
/// ```no_run
/// use qdrant_client::Qdrant;
///
///# async fn example(client: &Qdrant) -> Result<(), qdrant_client::QdrantError> {
/// let traced = client.with_header("x-request-id", "abc-123");
/// // traced shares the same connection pool, but adds the header to every request
///# Ok(())
///# }
/// ```
pub fn with_header(&self, key: impl Into<String>, value: impl Into<String>) -> Self {
let mut clone = self.clone();
clone.config.custom_headers.push((key.into(), value.into()));
clone
}

/// Health check.
///
/// Do a health check and fetch server information such as the current version and commit.
Expand Down
3 changes: 1 addition & 2 deletions tests/snippet_tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod test_batch_update;
mod test_clear_payload;
mod test_collection_exists;
mod test_config_headers;
Copy link

@dancixx dancixx Mar 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@generall why these tests are deleted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is autogenerated, I would need to look into it

mod test_count_points;
mod test_create_collection;
mod test_create_collection_with_bq;
Expand All @@ -21,7 +20,6 @@ mod test_delete_snapshot;
mod test_delete_vectors;
mod test_discover_batch_points;
mod test_discover_points;
mod test_external_api_keys;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same.

mod test_facets;
mod test_get_collection;
mod test_get_collection_aliases;
Expand Down Expand Up @@ -59,3 +57,4 @@ mod test_upsert_points;
mod test_upsert_points_fallback_shard_key;
mod test_upsert_points_insert_only;
mod test_upsert_points_with_condition;
mod test_with_header;
32 changes: 32 additions & 0 deletions tests/snippet_tests/test_with_header.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

#[tokio::test]
async fn test_with_header() {
async fn with_header() -> Result<(), Box<dyn std::error::Error>> {
// WARNING: This is a generated test snippet.
// Please, modify the snippet in the `../snippets/with_header.rs` file
use qdrant_client::Qdrant;

let client = Qdrant::from_url("http://localhost:6334")
.header("x-base", "base-value")
.skip_compatibility_check()
.build()
.unwrap();

let traced = client.with_header("x-request-id", "abc-123");

assert_eq!(
traced.config.custom_headers,
vec![
("x-base".to_string(), "base-value".to_string()),
("x-request-id".to_string(), "abc-123".to_string()),
]
);
// Original still has only the base header
assert_eq!(
client.config.custom_headers,
vec![("x-base".to_string(), "base-value".to_string())]
);
Ok(())
}
let _ = with_header().await;
}
22 changes: 22 additions & 0 deletions tests/snippets/with_header.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use qdrant_client::Qdrant;

let client = Qdrant::from_url("http://localhost:6334")
.header("x-base", "base-value")
.skip_compatibility_check()
.build()
.unwrap();

let traced = client.with_header("x-request-id", "abc-123");

assert_eq!(
traced.config.custom_headers,
vec![
("x-base".to_string(), "base-value".to_string()),
("x-request-id".to_string(), "abc-123".to_string()),
]
);
// Original still has only the base header
assert_eq!(
client.config.custom_headers,
vec![("x-base".to_string(), "base-value".to_string())]
);
Loading