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.
Comment From: ujaehrig
That was more than quick! Thank you very much!