-
Notifications
You must be signed in to change notification settings - Fork 671
Client: handle server responses with Content-Length: 0 #588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client: handle server responses with Content-Length: 0 #588
Conversation
if (contentType.isBlank()) { | ||
String contentLength = responseEvent.responseInfo() | ||
.headers() | ||
.firstValue("Content-Length") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a constant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
...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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Kehrlann !
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/html
ortext/plain
.Types of changes