Skip to content

feat(client): add Android HTTP client and remove fallback in factory#846

Open
sherryfox wants to merge 1 commit intoa2aproject:mainfrom
sherryfox:feat-android-http-client
Open

feat(client): add Android HTTP client and remove fallback in factory#846
sherryfox wants to merge 1 commit intoa2aproject:mainfrom
sherryfox:feat-android-http-client

Conversation

@sherryfox
Copy link
Copy Markdown

  • Port changes from PR 806 to main branch
  • Add AndroidA2AHttpClient using HttpURLConnection in a new extras module
  • Update A2AHttpClientFactory to fail fast if no provider is found
  • Add abstract test classes in http-client and concrete implementations in android module

Description

Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Follow the CONTRIBUTING Guide.
  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.
    • Important Prefixes for release-please:
      • fix: which represents bug fixes, and correlates to a SemVer patch.
      • feat: represents a new feature, and correlates to a SemVer minor.
      • feat!:, or fix!:, refactor!:, etc., which represent a breaking change (indicated by the !) and will result in a SemVer major.
  • Ensure the tests pass
  • Appropriate READMEs were updated (if necessary)

Related to #793 🦕

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new Android-specific HTTP client implementation using HttpURLConnection, along with its corresponding SPI provider and tests. The A2AHttpClientFactory has been refactored to cache providers and throw an exception if none are available, and the base http-client module now provides a test-jar for shared integration tests. Feedback highlights a resource leak in asynchronous POST requests, a potential memory exhaustion vulnerability when reading server responses, and a violation of the SSE specification regarding whitespace trimming. Additionally, it is recommended to use constants for connection timeouts.

Comment on lines +109 to +110
while ((line = reader.readLine()) != null) {
if (sb.length() + line.length() > maxResponseSize) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using reader.readLine() can lead to OutOfMemoryError if the server sends a very long line without a newline character, as readLine() buffers the entire line. Per repository rules, explicit size validation is necessary to prevent Denial of Service (DoS) via OutOfMemoryError. It is safer to read the stream in chunks while maintaining a running count of the total bytes read to ensure the final in-memory representation does not exceed safety limits.

References
  1. When a class is designed to hold the entire content of a file in memory, an explicit size validation is necessary to prevent Denial of Service (DoS) via OutOfMemoryError for arbitrarily large files.

@sherryfox sherryfox force-pushed the feat-android-http-client branch 3 times, most recently from dc263d2 to 9f312d6 Compare May 4, 2026 14:31
Copy link
Copy Markdown
Collaborator

@ehsavoie ehsavoie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SSE part will be treated in another PR as ikt affects the JdkHttpClient as well

@ehsavoie ehsavoie requested review from jmesnil and kabir May 5, 2026 07:06
Copy link
Copy Markdown
Collaborator

@ehsavoie ehsavoie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small fixes


@Override
public int priority() {
return 100; // Higher priority than JDK
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you switch this priority as it collides with the one from vertx http client

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added ANDROID_AVAILABLE to make it be highest priority only when running on Android, WDYT?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice :) this looks very good to me

@Override
public PostBuilder body(String body) {
this.body = body;
return this;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should return self(); shouldn't it ?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK They do the same thing here. self() is only needed in the base class for generics. In the subclass, return this works perfectly and avoids a method call and cast.

- Port changes from PR 806 to main branch
- Add AndroidA2AHttpClient using HttpURLConnection in a new extras module
- Update A2AHttpClientFactory to fail fast if no provider is found
- Add abstract test classes in http-client and concrete implementations in android module
@sherryfox sherryfox force-pushed the feat-android-http-client branch from 9f312d6 to 534e4e5 Compare May 5, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants