docs: document JDK HttpClient's restricted Host header and the Vert.x alternative by paulrutter · Pull Request #1180 · a2aproject/a2a-java · GitHub
Skip to content

docs: document JDK HttpClient's restricted Host header and the Vert.x alternative - #1180

Merged
kabir merged 3 commits into
a2aproject:mainfrom
paulrutter:docs/jdk-http-client-host-header-limitation
Sep 25, 2026
Merged

kabir merged 3 commits into
a2aproject:mainfrom
paulrutter:docs/jdk-http-client-host-header-limitation

Conversation

@paulrutter

Copy link
Copy Markdown
Contributor

java.net.http.HttpClient rejects an explicit "Host" header with an IllegalArgumentException unless the JVM is started with -Djdk.httpclient.allowRestrictedHeaders=host. This is a JDK-wide restriction, not something JdkA2AHttpClient can work around per-instance, and it wasn't documented anywhere, so callers who need a custom Host header (e.g. to reach an instance directly while presenting the hostname a load balancer would normally supply) had no clear path forward.

Document the restriction and the two ways around it: setting the JVM property, or using VertxA2AHttpClient (from the http-client-vertx extra), which does not build on java.net.http.HttpClient and has no such restriction. Add regression tests that lock in both behaviors: the JDK client rejecting the header, and the Vert.x client accepting it.

… alternative

java.net.http.HttpClient rejects an explicit "Host" header with an
IllegalArgumentException unless the JVM is started with
-Djdk.httpclient.allowRestrictedHeaders=host. This is a JDK-wide restriction,
not something JdkA2AHttpClient can work around per-instance, and it wasn't
documented anywhere, so callers who need a custom Host header (e.g. to reach
an instance directly while presenting the hostname a load balancer would
normally supply) had no clear path forward.

Document the restriction and the two ways around it: setting the JVM
property, or using VertxA2AHttpClient (from the http-client-vertx extra),
which does not build on java.net.http.HttpClient and has no such
restriction. Add regression tests that lock in both behaviors: the JDK
client rejecting the header, and the Vert.x client accepting it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019bxqScUGdfjts6YHbLfUPs

@kabir kabir left a comment

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.

Hi @paulrutter thank you for the PR.

Codex found these two issues. Do you agree? Feel free to argue against what it found if you don't agree :-)

Findings

  • P2 — The Vert.x example leaks resources. docs/content/dev/client.md:169 creates a VertxA2AHttpClient but never closes it. Its no-
    argument constructor starts a Vert.x instance, and JSONRPCTransport.close() does not close an injected HTTP client. Please show how
    to close both clients, or state that the HTTP client must be closed separately.

  • P3 — The JDK test fails when the documented workaround is enabled. JdkA2AHttpClientTest.java:80 always expects the Host header to be
    rejected. With -Djdk.httpclient.allowRestrictedHeaders=host set for the test JVM, the JDK accepts it and this assertion fails. Please
    make the test account for that supported configuration.

GitHub reports all PR checks passing. I did not run tests locally.

- docs/content/dev/client.md: show VertxA2AHttpClient being closed in the
  Host-header example. The no-args constructor owns a Vert.x instance, and
  JSONRPCTransport.close() is a no-op that never closes an injected
  A2AHttpClient, so the previous example leaked it.
- JdkA2AHttpClientTest: skip testCustomHostHeaderRejectedByJdkHttpClient when
  the JVM already allows a restricted Host header via
  -Djdk.httpclient.allowRestrictedHeaders=host, since the JDK client then
  legitimately accepts the header instead of rejecting it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019bxqScUGdfjts6YHbLfUPs
@paulrutter

paulrutter commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@kabir

kabir commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Thanks @paulrutter - I pushed a small fix regarding the closing of the clients to your branch.

@paulrutter

Copy link
Copy Markdown
Contributor Author

@kabir
kabir merged commit c2415a4 into a2aproject:main Sep 25, 2026
15 checks passed
@paulrutter
paulrutter deleted the docs/jdk-http-client-host-header-limitation branch September 25, 2026 16:44
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.

3 participants