chore(http-client): full test-coverage 1/2#162
Conversation
|
MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅ |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces significant improvements to the core HTTP client by refactoring its header caching mechanism for better performance and predictability. Concurrently, it vastly expands the unit test suite, ensuring comprehensive coverage of the HTTP protocol handling and connection pooling logic. These changes aim to make the HTTP client more robust, efficient, and easier to maintain by addressing edge cases and optimizing common request patterns. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
b34d7c1 to
ba7d842
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive unit test coverage for the HTTP API (HttpResponseProtocol, ConnectionPool, and HttpRequestTemplate) and simplifies the HttpRequestTemplate slow path by removing the per-call extra_headers dict-cache in favour of a single cached_headers bytes buffer populated once at setup time via cache_headers().
Changes:
- Removes the
_extra_headers_cachedict fromHttpRequestTemplate; the slow path now re-encodesextra_headerson every call, and callers are expected to usecache_headers()for headers that repeat on every request. - Renames
extra_cached_headers→cached_headers(now public). - Adds many new unit tests covering
HttpResponseProtocolerror paths (connection_lost,eof_received,data_receivedparser errors,iter_bodypre-buffered case,read_body/read_headersfast paths) andConnectionPooledge cases (stale-connection discard, idle timeout, waiter cancellation, unlimited pool, warmup, idempotent release).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/inference_endpoint/endpoint_client/http.py |
Removes _extra_headers_cache, renames extra_cached_headers → cached_headers, simplifies cache_headers() and slow-path in build_request() |
tests/unit/endpoint_client/test_http.py |
Deletes now-invalid cache tests, updates existing tests to match the new API, and adds ~10 new test cases for previously uncovered code paths |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ba7d842 to
b5748d1
Compare
There was a problem hiding this comment.
Code Review
The pull request refactors the HttpRequestTemplate class to simplify header caching. It replaces a dictionary-based cache (_extra_headers_cache) with a single byte string (cached_headers) for pre-encoded headers. The cache_headers method now directly appends new headers to this byte string, removing the logic for preventing duplicate header sets. The build_request method's 'slow path' for extra_headers no longer caches these headers, relying solely on cache_headers for pre-encoding. This change introduces a high-severity HTTP Header Injection vulnerability in both the cache_headers and build_request methods, as header values are directly embedded into strings without sanitization, allowing attackers to inject newline characters and arbitrary headers. Additionally, the simplified cache_headers method loses protection against duplicate headers, potentially leading to malformed requests if called multiple times with the same headers. The associated unit tests were updated to reflect these changes, including removing tests for the old caching mechanism and adding new tests for the updated HttpResponseProtocol behavior, such as handling connection loss and parser errors.
b5748d1 to
373537b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
373537b to
38caaba
Compare
src/inference_endpoint/endpoint_client/accumulator_protocol.py
Dismissed
Show dismissed
Hide dismissed
src/inference_endpoint/endpoint_client/accumulator_protocol.py
Dismissed
Show dismissed
Hide dismissed
src/inference_endpoint/endpoint_client/accumulator_protocol.py
Dismissed
Show dismissed
Hide dismissed
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
What does this PR do?
with this MR:
Type of change
Related issues
Testing
Checklist