Preserve all headers in response info #559
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Response headers were being filtered to exclude timing-dependent headers (
x-envoy-upstream-service-time,date,x-request-id) to avoid test flakiness. However, these headers can be useful for debugging, monitoring, and understanding request behavior in production environments.Additionally, the
extract_response_infofunction was importing modules on every request and performing unnecessary checks, creating performance overhead for a function that runs on every API call.Solution
Remove header filtering so all response headers are preserved in
_response_infofor REST, asyncio, and gRPC requests. This provides complete header information while maintaining correct equality comparisons (response dataclasses already exclude_response_infofrom equality checks).Also optimize
extract_response_infoperformance by moving imports to module level and removing unnecessary conditional checks.Changes
Response Info Extraction (
response_info.py)x-envoy-upstream-service-time,date,x-request-id)REST API Clients (
api_client.py,asyncio_api_client.py)extract_response_infoimport to module level to eliminate import overhead on every requestif response_info:check since the function always returns a dictPerformance Improvements
These optimizations are especially beneficial for high-throughput applications making many API calls.
Usage Example
No changes required for users - the API remains the same:
Testing
.get("raw_headers", {}), so they continue to work with additional headersBreaking Changes
None. This is a transparent improvement with no API changes. Response object equality comparisons are unaffected since
_response_infoalready hascompare=Falsein all response dataclasses (QueryResponse,UpsertResponse,UpdateResponse,FetchResponse,FetchByMetadataResponse).