Skip to content

DefaultWebClientBuilder copies references #25992

@ujaehrig

Description

@ujaehrig

The DefaultWebClientBuilder is copying references (e.g.defaul;tHeaders) to the built WebClient instance. This prevents reuse of the WebClient, as changing the content in the builder will also change the content in already created instances.

When the following snippet is used, both webClients will have the same defaultHeaders (i.e. X=second)

WebClient.Builder builder = WebClient.builder();
WebClient first = builder.defaultHeaders(h -> h.set("X", "first")).build;
WebClient second = builder.defaultHeaders(h -> h.set("X", "second")).build;

This can be experienced in Spring 5.2.8, but should be in the 5.3.0 as well.
It can be worked around by cloning the builder before change.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions