fix: Allow POST requests without Content-Type header when body is empty by kabir · Pull Request #759 · a2aproject/a2a-java · GitHub
Skip to content

fix: Allow POST requests without Content-Type header when body is empty - #759

Merged
kabir merged 2 commits into
a2aproject:mainfrom
kabir:issue-747
Mar 18, 2026
Merged

kabir merged 2 commits into
a2aproject:mainfrom
kabir:issue-747

Conversation

@kabir

@kabir kabir commented Mar 17, 2026

Copy link
Copy Markdown
Collaborator

Per RFC 9110 §8.3, Content-Type header is only meaningful when a message body is present. The HTTP+JSON transport was incorrectly returning 415 (ContentTypeNotSupportedError) for POST requests with no body and no Content-Type header.

This fix adds validateContentTypeForOptionalBody() method to handle endpoints like POST /tasks/{id}:cancel where the body is optional. When the body is null or empty, Content-Type validation is skipped. When body content is present, Content-Type must still be application/json.

This allows bodyless POST requests to be processed correctly and return appropriate errors (404 TaskNotFoundError, 409 TaskNotCancelableError) instead of 415.

Fixes #747 🦕

Per RFC 9110 §8.3, Content-Type header is only meaningful when a message
body is present. The HTTP+JSON transport was incorrectly returning 415
(ContentTypeNotSupportedError) for POST requests with no body and no
Content-Type header.

This fix adds validateContentTypeForOptionalBody() method to handle
endpoints like POST /tasks/{id}:cancel where the body is optional. When
the body is null or empty, Content-Type validation is skipped. When body
content is present, Content-Type must still be application/json.

This allows bodyless POST requests to be processed correctly and return
appropriate errors (404 TaskNotFoundError, 409 TaskNotCancelableError)
instead of 415.

Fixes a2aproject#747

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

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

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.

Code Review

This pull request correctly addresses an issue where POST requests with an empty body were incorrectly rejected due to a missing Content-Type header. The introduction of validateContentTypeForOptionalBody is a clean solution that correctly handles endpoints with optional bodies, like cancelTask. The implementation is sound and follows the logic described in the RFC. I have one minor suggestion to further improve the code.

Comment thread reference/rest/src/main/java/io/a2a/server/rest/quarkus/A2AServerRoutes.java Outdated
…verRoutes.java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@kabir
kabir merged commit 79cea44 into a2aproject:main Mar 18, 2026
11 checks passed
salaboy pushed a commit to salaboy/a2a-java that referenced this pull request Jun 19, 2026
…ty (a2aproject#759)

Per RFC 9110 §8.3, Content-Type header is only meaningful when a message
body is present. The HTTP+JSON transport was incorrectly returning 415
(ContentTypeNotSupportedError) for POST requests with no body and no
Content-Type header.

This fix adds validateContentTypeForOptionalBody() method to handle
endpoints like POST /tasks/{id}:cancel where the body is optional. When
the body is null or empty, Content-Type validation is skipped. When body
content is present, Content-Type must still be application/json.

This allows bodyless POST requests to be processed correctly and return
appropriate errors (404 TaskNotFoundError, 409 TaskNotCancelableError)
instead of 415.

Fixes a2aproject#747 🦕

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

[Bug]: HTTP+JSON transport returns 415 on POST requests without Content-Type header

2 participants