Expand description
Dynamic context provider for per-request context overrides.
This module provides the DynamicContextProvider trait that enables
per-request context injection (e.g., dynamic authentication headers).
§Usage
Implement the trait and pass to namespace builders:
ⓘ
use lance_namespace_impls::{RestNamespaceBuilder, DynamicContextProvider, OperationInfo};
use std::collections::HashMap;
use std::sync::Arc;
#[derive(Debug)]
struct MyProvider;
impl DynamicContextProvider for MyProvider {
fn provide_context(&self, info: &OperationInfo) -> HashMap<String, String> {
let mut context = HashMap::new();
context.insert("headers.Authorization".to_string(), format!("Bearer {}", get_current_token()));
context.insert("headers.X-Request-Id".to_string(), generate_request_id());
context
}
}
let namespace = RestNamespaceBuilder::new("https://api.example.com")
.context_provider(Arc::new(MyProvider))
.build();For RestNamespace, context keys that start with headers. are converted to HTTP headers
by stripping the prefix. For example, {"headers.Authorization": "Bearer abc123"}
becomes the Authorization: Bearer abc123 header. Keys without the headers. prefix
are ignored for HTTP headers but may be used for other purposes.
Structs§
- Operation
Info - Information about the namespace operation being executed.
Traits§
- Dynamic
Context Provider - Trait for providing dynamic request context.