-
Notifications
You must be signed in to change notification settings - Fork 3.5k
docs: document that SimpleClientHttpRequestFactory is not suitable for WebMVC gateway #4196
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
Open
won-seoop
wants to merge
1
commit into
spring-cloud:main
Choose a base branch
from
won-seoop:doc-webmvc-unsuitable-http-client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+63
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
62 changes: 62 additions & 0 deletions
62
docs/modules/ROOT/pages/spring-cloud-gateway-server-webmvc/http-client.adoc
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| [[http-client]] | ||
| = HTTP Client | ||
|
|
||
| Spring Cloud Gateway Server MVC uses Spring Boot's `RestClient` infrastructure to forward requests to backend services. | ||
| The underlying `ClientHttpRequestFactory` is resolved from the application context, driven by `spring.http.clients.imperative.factory`. | ||
|
|
||
| IMPORTANT: `SimpleClientHttpRequestFactory` (backed by `java.net.HttpURLConnection`) is **not suitable** for the WebMVC gateway. | ||
| `HttpURLConnection` throws a `java.io.IOException` (such as `FileNotFoundException` for 404 responses) instead of providing the response body for 4xx/5xx status codes. | ||
| The gateway cannot forward error responses correctly in this case, and the client will receive an `HTTP 500` instead of the actual upstream error status. | ||
|
|
||
| == Selecting an HTTP Client | ||
|
|
||
| Use one of the following supported implementations: | ||
|
|
||
| === JDK HttpClient (recommended, no extra dependency) | ||
|
|
||
| Set the factory to `jdk` to use Java's built-in `HttpClient` (available since Java 11): | ||
|
|
||
| .application.yml | ||
| [source,yaml] | ||
| ---- | ||
| spring: | ||
| http: | ||
| clients: | ||
| imperative: | ||
| factory: jdk | ||
| ---- | ||
|
|
||
| === OkHttp | ||
|
|
||
| Add `com.squareup.okhttp3:okhttp` to your classpath. The factory is selected automatically when `okhttp3.OkHttpClient` is on the classpath, or you can set it explicitly: | ||
|
|
||
| .application.yml | ||
| [source,yaml] | ||
| ---- | ||
| spring: | ||
| http: | ||
| clients: | ||
| imperative: | ||
| factory: okhttp | ||
| ---- | ||
|
|
||
| === Apache HttpComponents | ||
|
|
||
| Add `org.apache.httpcomponents.client5:httpclient5` to your classpath, or set the factory explicitly: | ||
|
|
||
| .application.yml | ||
| [source,yaml] | ||
| ---- | ||
| spring: | ||
| http: | ||
| clients: | ||
| imperative: | ||
| factory: apache | ||
| ---- | ||
|
|
||
| NOTE: If you have OkHttp or Apache HttpComponents on the classpath, Spring Boot's auto-detection will prefer them over `SimpleClientHttpRequestFactory`, so the IMPORTANT notice above only applies when running without any of those libraries. | ||
|
|
||
| == Related Documentation | ||
|
|
||
| * xref:spring-cloud-gateway-server-webmvc/tls-and-ssl.adoc[TLS and SSL] – configure SSL bundles for backend calls | ||
| * https://docs.spring.io/spring-boot/reference/io/rest-client.html#io.rest-client.restclient[Spring Boot RestClient documentation] | ||
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.
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.
This does not need to be done as it is the default