File tree Expand file tree Collapse file tree 4 files changed +76
-2
lines changed
Expand file tree Collapse file tree 4 files changed +76
-2
lines changed Original file line number Diff line number Diff line change @@ -212,6 +212,27 @@ impl Qdrant {
212212 Ok(result)
213213 }
214214
215+ /// Create a lightweight clone of this client with an additional header.
216+ ///
217+ /// The returned client shares the same connection pool but sends
218+ /// the extra header with every request. Useful for per-request
219+ /// tracing IDs or other contextual metadata.
220+ ///
221+ /// ```no_run
222+ /// use qdrant_client::Qdrant;
223+ ///
224+ ///# async fn example(client: &Qdrant) -> Result<(), qdrant_client::QdrantError> {
225+ /// let traced = client.with_header("x-request-id", "abc-123");
226+ /// // traced shares the same connection pool, but adds the header to every request
227+ ///# Ok(())
228+ ///# }
229+ /// ```
230+ pub fn with_header(&self, key: impl Into<String>, value: impl Into<String>) -> Self {
231+ let mut clone = self.clone();
232+ clone.config.custom_headers.push((key.into(), value.into()));
233+ clone
234+ }
235+
215236 /// Health check.
216237 ///
217238 /// Do a health check and fetch server information such as the current version and commit.
Original file line number Diff line number Diff line change 11mod test_batch_update;
22mod test_clear_payload;
33mod test_collection_exists;
4- mod test_config_headers;
54mod test_count_points;
65mod test_create_collection;
76mod test_create_collection_with_bq;
@@ -21,7 +20,6 @@ mod test_delete_snapshot;
2120mod test_delete_vectors;
2221mod test_discover_batch_points;
2322mod test_discover_points;
24- mod test_external_api_keys;
2523mod test_facets;
2624mod test_get_collection;
2725mod test_get_collection_aliases;
@@ -59,3 +57,4 @@ mod test_upsert_points;
5957mod test_upsert_points_fallback_shard_key;
6058mod test_upsert_points_insert_only;
6159mod test_upsert_points_with_condition;
60+ mod test_with_header;
Original file line number Diff line number Diff line change 1+
2+ #[tokio::test]
3+ async fn test_with_header() {
4+ async fn with_header() -> Result<(), Box<dyn std::error::Error>> {
5+ // WARNING: This is a generated test snippet.
6+ // Please, modify the snippet in the `../snippets/with_header.rs` file
7+ use qdrant_client::Qdrant;
8+
9+ let client = Qdrant::from_url("http://localhost:6334")
10+ .header("x-base", "base-value")
11+ .skip_compatibility_check()
12+ .build()
13+ .unwrap();
14+
15+ let traced = client.with_header("x-request-id", "abc-123");
16+
17+ assert_eq!(
18+ traced.config.custom_headers,
19+ vec![
20+ ("x-base".to_string(), "base-value".to_string()),
21+ ("x-request-id".to_string(), "abc-123".to_string()),
22+ ]
23+ );
24+ // Original still has only the base header
25+ assert_eq!(
26+ client.config.custom_headers,
27+ vec![("x-base".to_string(), "base-value".to_string())]
28+ );
29+ Ok(())
30+ }
31+ let _ = with_header().await;
32+ }
Original file line number Diff line number Diff line change 1+ use qdrant_client::Qdrant;
2+
3+ let client = Qdrant::from_url("http://localhost:6334")
4+ .header("x-base", "base-value")
5+ .skip_compatibility_check()
6+ .build()
7+ .unwrap();
8+
9+ let traced = client.with_header("x-request-id", "abc-123");
10+
11+ assert_eq!(
12+ traced.config.custom_headers,
13+ vec![
14+ ("x-base".to_string(), "base-value".to_string()),
15+ ("x-request-id".to_string(), "abc-123".to_string()),
16+ ]
17+ );
18+ // Original still has only the base header
19+ assert_eq!(
20+ client.config.custom_headers,
21+ vec![("x-base".to_string(), "base-value".to_string())]
22+ );
You can’t perform that action at this time.
0 commit comments