Class ClientBuilder


public final class ClientBuilder
extends AbstractClientOptionsBuilder
Creates a new client that connects to the specified URI using the builder pattern. Use the factory methods in Clients if you do not have many options to override. If you are creating an WebClient, it is recommended to use the WebClientBuilder or factory methods in WebClient.

How are decorators and HTTP headers configured?

Unlike other options, when a user calls option(ClientOption, Object) or options() with a ClientOption.DECORATION or a ClientOption.HTTP_HEADERS, this builder will not simply replace the old option but merge the specified option into the previous option value. For example:


 ClientOptionsBuilder b = ClientOptions.builder();
 b.option(ClientOption.HTTP_HEADERS, headersA);
 b.option(ClientOption.HTTP_HEADERS, headersB);
 b.option(ClientOption.DECORATION, decorationA);
 b.option(ClientOption.DECORATION, decorationB);

 ClientOptions opts = b.build();
 HttpHeaders httpHeaders = opts.httpHeaders();
 ClientDecoration decorations = opts.decoration();
 
httpHeaders will contain all HTTP headers of headersA and headersB. If headersA and headersB have the headers with the same name, the duplicate header in headerB will replace the one with the same name in headerA. Similarly, decorations will contain all decorators of decorationA and decorationB, but there will be no replacement but only addition.