Enhance HttpHandler API to support separate connection and read timeouts#87
Conversation
- Remove old requestTimeoutSeconds method completely as per issue requirements - Add new connectionTimeoutSeconds() and readTimeoutSeconds() methods to builder - Update HttpHandler constructor to accept separate timeouts - Update HttpClient creation to use connection timeout and HttpRequest to use read timeout - Add validation for both timeout parameters - Update all test cases to use new separate timeout API - Update documentation examples to show new API usage Resolves #86
There was a problem hiding this comment.
Summary of Changes
Hello @cuioss, 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 refactors the HttpHandler API to offer more granular control over HTTP request timeouts by introducing separate connection and read timeout configurations. This change improves the precision of timeout handling, provides clearer API semantics, and enhances error handling by allowing applications to distinguish between connection establishment failures and slow response reading, bringing the API in line with industry standards.
Highlights
- API Enhancement: The
HttpHandlerAPI has been enhanced to provide separate control over connection and read timeouts, addressing issue #86. This replaces the singlerequestTimeoutSecondswith distinctconnectionTimeoutSecondsandreadTimeoutSecondsmethods in the builder. - Timeout Application: Connection timeout is now applied to
HttpClient.Builder.connectTimeout(Duration), and read timeout is applied toHttpRequest.Builder.timeout(Duration), aligning with standard HTTP client practices. - Default Values & Validation: Both connection and read timeouts now default to 10 seconds. New validation has been added to ensure both timeout parameters are positive integers, throwing
IllegalArgumentExceptionotherwise. - Builder and Test Updates: The
HttpHandlerBuilderandasBuilder()methods have been updated to correctly handle and preserve the new separate timeout parameters. All relevant unit tests inHttpHandlerTest.javahave been updated and new tests added to cover the new timeout validation and behavior.
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and 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 to provide feedback.
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
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
The pull request introduces separate connection and read timeouts in the HttpHandler API. The changes include removing the old requestTimeoutSeconds method, adding separate connectionTimeoutSeconds() and readTimeoutSeconds() methods to the builder, updating the constructor and HttpClient/HttpRequest creation to use the new timeouts, and adding validation for the timeout parameters. The tests have been updated to use the new API and include comprehensive tests for timeout validation.
- Updated license headers for all Java source files - Applied code formatting and static analysis rules - All tests pass successfully
|



Enhancement: Support Separate Connection and Read Timeouts in HttpHandler
This PR implements the enhancement requested in issue #86 to support separate connection and read timeouts in the
HttpHandlerAPI.Changes Made
HttpHandler.java
requestTimeoutSecondsmethod completely (as per issue requirements - no backward compatibility needed)connectionTimeoutSeconds()andreadTimeoutSeconds()methods to the builderHttpClientcreation to use connection timeout viaconnectTimeout(Duration)HttpRequestcreation to use read timeout viatimeout(Duration)HttpHandlerTest.java
asBuilder()tests to verify both timeouts are preservedAPI Changes
Before:
After:
Benefits
Implementation Details
HttpClient.Builder.connectTimeout(Duration)HttpRequest.Builder.timeout(Duration)asBuilder()method correctly preserves both timeout valuesTesting
Closes #86