question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ApacheDockerHttpClient builder support customize httpclient's RequestConfig and PoolingHttpClientConnectionManager

See original GitHub issue

Hi guys, I am using docker-java to implement my business, I love this library and I found I cannot cusomize ApacheDockerHttpClient’ HttpClient request configs. I am initializing ApacheDockerHttpClient instance with this code:

return new ApacheDockerHttpClient.Builder()
                .dockerHost(dockerClientConfig.getDockerHost())
                .sslConfig(dockerClientConfig.getSSLConfig())
                .build();

I have view the source code, and may be you guys can change the ApacheDockerHttpClientImpl scope to support caller change httpClient properties?

Just return HttpClientBuilder instead HttpClient will be more flexiable

httpClient = HttpClients.custom()
            .setRequestExecutor(new HijackingHttpRequestExecutor(null))
            .setConnectionManager(new PoolingHttpClientConnectionManager(
                socketFactoryRegistry,
                new ManagedHttpClientConnectionFactory(
                    null,
                    null,
                    null,
                    null,
                    message -> {
                        Header transferEncodingHeader = message.getFirstHeader(HttpHeaders.TRANSFER_ENCODING);
                        if (transferEncodingHeader != null) {
                            if ("identity".equalsIgnoreCase(transferEncodingHeader.getValue())) {
                                return ContentLengthStrategy.UNDEFINED;
                            }
                        }
                        return DefaultContentLengthStrategy.INSTANCE.determineLength(message);
                    },
                    null
                )
            ))
            .build();

Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
richard-yaocommented, Aug 18, 2020

Hi @bsideup

Thanks for your answer.

I want to change the default max connections per route property in PoolingHttpClientConnectionManager class, I have used httpclient in other business service, I noticed that in PoolingHttpClientConnectionManager source code

public static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 25;
public static final int DEFAULT_MAX_CONNECTIONS_PER_ROUTE = 5;

I want customize these parameters to fit different machine’s performance.

And the HttpClients.custom().build() method using default RequestConfig with these parameters:

private static final Timeout DEFAULT_CONNECTION_REQUEST_TIMEOUT = Timeout.ofMinutes(3);
private static final Timeout DEFAULT_CONNECT_TIMEOUT = Timeout.ofMinutes(3);
private static final TimeValue DEFAULT_CONN_KEEP_ALIVE = TimeValue.ofMinutes(3);

The default timeout for my business is not very suitable, I want to decrease the connectTimeout

0reactions
daigaigai520commented, Dec 10, 2020

why closed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apache HttpClient Connection Management - Baeldung
The PoolingHttpClientConnectionManager will create and manage a pool of connections for each route or target host we use. The default size of ...
Read more >
RequestConfig.Builder (Apache HttpClient 5.2.1 API)
Determines the order of preference for supported authentication schemes by their names when authenticating with the target host. Methods inherited from class ...
Read more >
RequestConfig.Builder (Apache HttpClient 4.5.8 API)
Object extended by org.apache.http.client.config.RequestConfig.Builder ... Builder; extends Object ... (4.4) Use PoolingHttpClientConnectionManager.
Read more >
org.apache.http.client.config.RequestConfig.custom java code ...
builder.setMaxConnPerRoute(50); builder.setMaxConnTotal(100); CloseableHttpClient httpclient = builder.build(); URI uri = new URIBuilder(url).build(); ...
Read more >
How to write tests on HTTP client apache? - Stack Overflow
Javalin would be an excellent tool for mocking the real service as it allows for state assertions in your tests.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found