Skip to content

Add builder support for SimpleClientHttpRequestFactory #35100

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

Closed

Conversation

jminkkk
Copy link

@jminkkk jminkkk commented Jun 23, 2025

I would like to propose adding a Builder pattern to SimpleClientHttpRequestFactory in order to support fluent and immutable configuration of commonly used properties such as connectTimeout, readTimeout, proxy, and chunkSize.

Current usage example (mutable setters):

SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setConnectTimeout(3000);
factory.setReadTimeout(5000);
factory.setProxy(Proxy.NO_PROXY);
factory.setChunkSize(2048);

Proposed usage example (fluent builder):

SimpleClientHttpRequestFactory factory = SimpleClientHttpRequestFactory.builder()
    .connectTimeout(3000)
    .readTimeout(5000)
    .proxy(Proxy.NO_PROXY)
    .chunkSize(2048)
    .build();

Motivation

The current mutable setter approach requires multiple separate calls and can lead to partially configured instances. A builder pattern enables fluent, thread-safe, and immutable configuration, improving readability and reducing errors. This approach is consistent with the design trends observed in several modern Spring APIs that have adopted or are adopting the builder pattern, helping to provide a more fluent and robust developer experience.

Proposal

Add a static nested Builder class with chainable setters and a build() method returning an immutable, fully configured SimpleClientHttpRequestFactory.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 23, 2025
- Implemented Builder pattern for configuring connectTimeout and readTimeout
- Added tests to verify timeout values are applied on HttpURLConnection

Signed-off-by: ‘jminkkk’ <[email protected]>
@jminkkk jminkkk force-pushed the builder-timeout-support branch from 5538f8c to 7228deb Compare June 23, 2025 18:14
@bclozel bclozel added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jun 24, 2025
Copy link
Contributor

@rstoyanchev rstoyanchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many ClientHttpRequestFactory implementations, and I don't think we should decide on whether to add builders one at at time.

Generally, these factories are infrastructure components that are configured from a single place, so having a builder doesn't make a big difference, and I don't think we should be adding them across all factories.

SimpleClientHttpRequestFactory is not a mainstream choice. For most cases you need to upgrade to one of the other HTTP client library choices, and nowadays there is also a replacement in the JDK with java.net.http.HttpClient.

Spring Boot provides infrastructure and abstractions for configuring request factories that supersedes direct use of the request factories.

For all these reasons, I don't think we will process this, but thanks for the suggestion in any case.

@rstoyanchev rstoyanchev added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants