Skip to content
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

Investigate applying ReactorNettyHttpClientMapper beans to the HttpClient used by an auto-configured ReactorClientHttpRequestFactoryBuilder #43365

Open
kzander91 opened this issue Dec 3, 2024 · 2 comments
Labels
status: pending-design-work Needs design work before any code can be developed type: enhancement A general enhancement
Milestone

Comments

@kzander91
Copy link
Contributor

I'm trying out the new HTTP client enhancements made with 3.4.0 and noticed:

  • spring.http.client properties don't apply to auto-configured WebClient.Builder instances.
  • My ReactorNettyHttpClientMapper beans are not applied to the HttpClient created by ReactorClientHttpRequestFactoryBuilder.

I was hoping to be able to simplify my configuration by re-using the same (or rather identically configured) Reactor HttpClient instances across my WebClient and RestTemplate beans, but it looks like I still need to configure those separatedly.

Are there plans to harmonize the configuration to allow the new properties and existing customizers like ReactorNettyHttpClientMapper to apply globally to all auto-configured HTTP clients?

Related:

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 3, 2024
@wilkinsona
Copy link
Member

spring.http.client properties don't apply to auto-configured WebClient.Builder instances

This is to be expected and documented. The properties are for Spring's blocking HTTP clients only, naming RestTemplate and RestClient.

I was hoping to be able to simplify my configuration by re-using the same (or rather identically configured) Reactor HttpClient instances across my WebClient and RestTemplate beans, but it looks like I still need to configure those separatedly.

That's right. At the moment, ReactorNettyHttpClientMapper beans are only applied when creating the ReactorClientHttpConnector used by WebClient. As things stand, I think you could apply them yourself through ReactorClientHttpRequestFactoryBuilder.withHttpClientCustomizer(UnaryOperator<HttpClient>):

@Bean
ClientHttpRequestFactoryBuilder<?> clientHttpRequestFactoryBuilder(
		ObjectProvider<ReactorNettyHttpClientMapper> mappers) {
	ReactorClientHttpRequestFactoryBuilder reactor = ClientHttpRequestFactoryBuilder.reactor();
	mappers.forEach((mapper) -> reactor.withHttpClientCustomizer(mapper::configure));
	return reactor;
}

I think we can re-purpose this issue to investigate doing the above automatically when the auto-configured ClientHttpRequestFactoryBuilder is a ReactorClientHttpRequestFactoryBuilder.

@wilkinsona wilkinsona changed the title spring.http.client properties do not apply to auto-configured WebClient.Builder Investigate applying ReactorNettyHttpClientMapper beans to the HttpClient used by an auto-configured ReactorClientHttpRequestFactoryBuilder Dec 3, 2024
@wilkinsona wilkinsona added type: enhancement A general enhancement status: pending-design-work Needs design work before any code can be developed and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 3, 2024
@wilkinsona wilkinsona added this to the 3.x milestone Dec 3, 2024
@kzander91
Copy link
Contributor Author

@wilkinsona Thanks for the quick response, defining my own ClientHttpRequestFactoryBuilder is the workaround I'll be going with for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pending-design-work Needs design work before any code can be developed type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants