Repository navigation
feat: support per-request header override - #2631
Conversation
westonpace
left a comment
There was a problem hiding this comment.
A few suggestions for cleanup but looks ok to me
| Thread Safety | ||
| ------------- | ||
| Implementations should be thread-safe as get_headers() may be called | ||
| concurrently from multiple threads. Use locks or other synchronization | ||
| primitives if your implementation maintains mutable state. |
There was a problem hiding this comment.
This would only be a problem if the header provider called into underlying C routines right? A pure python header provider doesn't need to worry?
| with self._refresh_lock: | ||
| # Check again inside the lock in case another thread refreshed | ||
| if self._needs_refresh(): | ||
| token_data = self._token_fetcher() |
There was a problem hiding this comment.
Is this going to do blocking I/O?
| #[async_trait] | ||
| impl lancedb::remote::HeaderProvider for PyHeaderProvider { | ||
| async fn get_headers(&self) -> lancedb::error::Result<HashMap<String, String>> { | ||
| self.get_headers_internal() |
There was a problem hiding this comment.
Should we spawn this call on a dedicated blocking task with tokio's spawn_blocking?
| /// A wrapper around a Python HeaderProvider that can be called from Rust | ||
| #[derive(Clone)] | ||
| pub struct PyHeaderProvider { | ||
| provider: Arc<RwLock<Option<Py<PyAny>>>>, |
There was a problem hiding this comment.
Does this need to be an async mutex? It looks like it only gets set once from the constructor. Actually, is a mutex needed here at all? It doesn't look like this is ever modified.
There was a problem hiding this comment.
yes you are right, originally I implemented the python HeaderProvider async, let me remove this
| } | ||
|
|
||
| /// Get headers from the Python provider (internal implementation) | ||
| async fn get_headers_internal(&self) -> Result<HashMap<String, String>, String> { |
There was a problem hiding this comment.
This method could be sync if you get rid of the async mutex
Add HeaderProvider authentication system for dynamic header management: - Python HeaderProvider abstract base class with StaticHeaderProvider and OAuthProvider implementations - Rust FFI bridge to call Python providers from Rust code - HTTP client modifications to apply dynamic headers before each request - Comprehensive test coverage for all authentication patterns This enables OAuth token refresh, API key rotation, and custom authentication schemes. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
36ef4bd to
2d48e84
Compare
|
looks like there is in general a problem that building the lancedb wheel for doc code testing take a long time, I will publish another PR to fix that, and merge this for a prerelease first. |
…4632) ## Summary #3971 added `test_zero_lifetime_token_is_refreshed`, but its expected headers omit `x-lancedb-credential-type: oidc`, which `OAuthProvider.get_headers()` has emitted since #2631/#4070. The test fails against current main and breaks the PR CI matrix for every open PR. ## Changes - Align the two zap assertions in `test_zero_lifetime_token_is_refreshed` with the provider contract (see `test_token_refresh` and `test_sync_method`). ## Tests - `pytest python/tests/test_header_provider.py -q`
Summary
This PR introduces a
HeaderProviderwhich is called for all remote HTTP calls to get the latest headers to inject. This is useful for features like adding the latest auth tokens where the header provider can auto-refresh tokens internally and each request always set the refreshed token.