Client: handle server responses with Content-Length: 0#588
Merged
Conversation
chemicL
reviewed
Oct 1, 2025
| if (contentType.isBlank()) { | ||
| String contentLength = responseEvent.responseInfo() | ||
| .headers() | ||
| .firstValue("Content-Length") |
Contributor
Author
There was a problem hiding this comment.
Happy to use a constant but it is inconsistent with the rest of the file (e.g. instances of Content-Type, a Cache-Control and an Access).
In that case I think we should standardize the whole transport. Agreed?
Member
There was a problem hiding this comment.
Yep, let's add the headers to the HttpHeaders class since they are either part of the specification of the HTTP-based remote transports or are simply needed to make it work. Last-Event-ID is not MCP specific but is part of the MCP remote transport logic so there's no need to think of other places for the common header names.
chemicL
reviewed
Oct 1, 2025
...rc/main/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransport.java
Outdated
Show resolved
Hide resolved
- When the client sends `notification/initalized`, servers must respond with HTTP 202 and an empty body. We checked for the absence of a Content-Type header to verify whether the body was empty. - However, some servers will send an empty body with a Content-Type header, and that header may have an unsupported, default type such as `text/html` or `text/plain`. - Now we we also use the Content-Length header to check for an empty body. This header is optional in HTTP/2, so we do not make it our primary mechanism for detecting empty bodies. - As part of this PR, we also move hard-coded HTTP header names to the HttpHeaders interface. While they are not defined by the MCP spec, they are used by it and are core to implementing the protocol. Therefore, they have their place in a core interface. - Fixes #582 Signed-off-by: Daniel Garnier-Moiroux <git@garnier.wf>
c4bf139 to
bb125d8
Compare
chemicL
approved these changes
Oct 1, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
notification/initalized, servers MUST respond with HTTP 202 and an empty body. Before this PR, we checked for the absence of a Content-Type header to know whether the body was empty.text/htmlortext/plain.Types of changes