fix: HttpClientStreamableHttpTransport redirect#520
fix: HttpClientStreamableHttpTransport redirect#520Zizo-Vi wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
|
@Zizo-Vi i believe this can easily be resolved with configuration: #433 (comment) |
|
My stance is that we provide the default with whatever opinions the defaults are in the HttpClient. There is a way to inject your own configuration but we should not override the defaults as it can lead to security issues and should be a conscious choice of the user. |
|
I will close this PR because following codes can easily resole related issue. HttpClient.Builder clientBuilder = HttpClient.newBuilder().version(HttpClient.Version.HTTP_1_1).followRedirects(HttpClient.Redirect.NORMAL); HttpClientStreamableHttpTransport transport = HttpClientStreamableHttpTransport.builder(some url ) |
|
Closed as resolved by configuration: #520 (comment) |
This PR updates the HttpClientStreamableHttpTransport to automatically handle HTTP redirects, such as 307 Temporary Redirect.
Resolve: #433
Motivation and Context
Currently, the HttpClientStreamableHttpTransport does not handle HTTP redirects. The underlying java.net.http.HttpClient defaults to a redirect policy of NEVER. Consequently, when an MCP server returns a 307 status code, the client fails to follow the redirect and throws an error. This change configures the HTTP client to automatically follow redirects, making the transport more robust and compliant with standard HTTP behavior.
How Has This Been Tested?
This was tested by pointing the client to a server endpoint that issues a 307 Temporary Redirect. Before this change, the client would fail. With this change, the client successfully follows the redirect and establishes a connection with the new endpoint.
Breaking Changes
Types of changes
Checklist
Additional context
The fix is applied by setting the followRedirects policy to HttpClient.Redirect.NORMAL in the HttpClient.Builder. This enables the client to handle common redirect status codes (301, 302, 307, 308) automatically.