protected ConfiguredCloseableHttpClient createClient(
            final org.apache.hc.client5.http.impl.classic.HttpClientBuilder builder,
            final InstrumentedHttpClientConnectionManager manager,
            final String name) {
        final String cookiePolicy = configuration.isCookiesEnabled() ? StandardCookieSpec.RELAXED : StandardCookieSpec.IGNORE;
        final int timeout = (int) configuration.getTimeout().toMilliseconds();
        final int connectionTimeout = (int) configuration.getConnectionTimeout().toMilliseconds();
        final int connectionRequestTimeout = (int) configuration.getConnectionRequestTimeout().toMilliseconds();
        final long keepAlive = configuration.getKeepAlive().toMilliseconds();
        final ConnectionReuseStrategy reuseStrategy = keepAlive == 0
                ? ((request, response, context) -> false)
                : new DefaultConnectionReuseStrategy();
        final HttpRequestRetryStrategy retryHandler = configuration.getRetries() == 0
                ? NO_RETRIES
                : (httpRequestRetryStrategy == null ? new DefaultHttpRequestRetryStrategy(configuration.getRetries(),
                TimeValue.ofSeconds(1L)) : httpRequestRetryStrategy);

        final RequestConfig requestConfig
                = RequestConfig.custom().setCookieSpec(cookiePolicy)
                .setResponseTimeout(timeout, TimeUnit.MILLISECONDS)
                .setConnectTimeout(connectionTimeout, TimeUnit.MILLISECONDS)
                .setConnectionKeepAlive(TimeValue.of(-1, TimeUnit.MILLISECONDS))
                .setConnectionRequestTimeout(connectionRequestTimeout, TimeUnit.MILLISECONDS)
                .build();
        final SocketConfig socketConfig = SocketConfig.custom()
                .setTcpNoDelay(true)
                .setSoTimeout(timeout, TimeUnit.MILLISECONDS)
                .build();

        manager.setDefaultSocketConfig(socketConfig);

        builder.setRequestExecutor(createRequestExecutor(name))
            .setConnectionManager(manager)
            .setDefaultRequestConfig(requestConfig)
            .setConnectionReuseStrategy(reuseStrategy)
            .setRetryStrategy(retryHandler)
            .setUserAgent(createUserAgent(name));

        if (keepAlive != 0) {
            // either keep alive based on response header Keep-Alive,
            // or if the server can keep a persistent connection (-1), then override based on client's configuration
            builder.setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy() {
                @Override
                public TimeValue getKeepAliveDuration(HttpResponse response, HttpContext context) {
                    final TimeValue duration = super.getKeepAliveDuration(response, context);
                    return (duration.getDuration() == -1) ? TimeValue.ofMilliseconds(keepAlive) : duration;
                }
            });
        }

        // create a tunnel through a proxy host if it's specified in the config
        final ProxyConfiguration proxy = configuration.getProxyConfiguration();
        if (proxy != null) {
            final HttpHost httpHost = new HttpHost(proxy.getScheme(), proxy.getHost(), proxy.getPort());
            builder.setRoutePlanner(new NonProxyListProxyRoutePlanner(httpHost, proxy.getNonProxyHosts()));
            // if the proxy host requires authentication then add the host credentials to the credentials provider
            final AuthConfiguration auth = proxy.getAuth();
            if (auth != null) {
                if (credentialsStore == null) {
                    credentialsStore = new BasicCredentialsProvider();
                }
                // set the AuthScope
                AuthScope authScope = new AuthScope(httpHost, auth.getRealm(), auth.getAuthScheme());

                // set the credentials type
                Credentials credentials = configureCredentials(auth);

                credentialsStore.setCredentials(authScope, credentials);
            }
        }

        if (credentialsStore != null) {
            builder.setDefaultCredentialsProvider(credentialsStore);
        }

        if (routePlanner != null) {
            builder.setRoutePlanner(routePlanner);
        }

        if (disableContentCompression) {
            builder.disableContentCompression();
        }

        if (redirectStrategy != null) {
            builder.setRedirectStrategy(redirectStrategy);
        }

        if (defaultHeaders != null) {
            builder.setDefaultHeaders(defaultHeaders);
        }

        if (httpProcessor != null) {
            builder.addRequestInterceptorFirst(httpProcessor);
            builder.addResponseInterceptorLast(httpProcessor);
        }

        customizeBuilder(builder);

        return new ConfiguredCloseableHttpClient(builder.build(), requestConfig);
    }
@Test
    void exposedConfigIsTheSameAsInternalToTheWrappedHttpClient() {
        ConfiguredCloseableHttpClient client = builder.createClient(apacheBuilder, connectionManager, "test");
        assertThat(client).isNotNull();

        assertThat(client.getClient()).extracting("defaultConfig").isEqualTo(client.getDefaultRequestConfig());
    }