Search in sources :

Example 1 with ClientTlsStrategyBuilder

use of org.apache.hc.client5.http.ssl.ClientTlsStrategyBuilder in project bender by Nextdoor.

the class AbstractHttp2TransportFactory method getClientBuilder.

protected HttpAsyncClientBuilder getClientBuilder(boolean useSSL, String url, Map<String, String> stringHeaders) {
    HttpAsyncClientBuilder cb = HttpAsyncClients.custom();
    PoolingAsyncClientConnectionManagerBuilder cmb = PoolingAsyncClientConnectionManagerBuilder.create();
    /*
     * Setup SSL
     */
    if (useSSL) {
        final ClientTlsStrategyBuilder tsb = ClientTlsStrategyBuilder.create().setSslContext(getSSLContext()).setTlsVersions(TLS.V_1_3, TLS.V_1_2).setHostnameVerifier(new HostnameVerifier() {

            public boolean verify(String s, SSLSession sslSession) {
                return true;
            }
        });
        cmb = cmb.setTlsStrategy(tsb.build());
    }
    /*
     * Add default headers
     */
    ArrayList<BasicHeader> headers = new ArrayList<BasicHeader>(stringHeaders.size());
    stringHeaders.forEach((k, v) -> headers.add(new BasicHeader(k, v)));
    cb = cb.setDefaultHeaders(headers);
    /*
     * Pool concurrency settings
     */
    cmb = cmb.setMaxConnPerRoute(this.config.getThreads()).setMaxConnTotal(this.config.getThreads()).setPoolConcurrencyPolicy(PoolConcurrencyPolicy.STRICT);
    /*
     * Negotiate on HTTP version with the server
     */
    cb = cb.setVersionPolicy(HttpVersionPolicy.NEGOTIATE);
    return cb.setConnectionManager(cmb.build());
}
Also used : PoolingAsyncClientConnectionManagerBuilder(org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder) ClientTlsStrategyBuilder(org.apache.hc.client5.http.ssl.ClientTlsStrategyBuilder) SSLSession(javax.net.ssl.SSLSession) ArrayList(java.util.ArrayList) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) HttpAsyncClientBuilder(org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Aggregations

ArrayList (java.util.ArrayList)1 HostnameVerifier (javax.net.ssl.HostnameVerifier)1 SSLSession (javax.net.ssl.SSLSession)1 HttpAsyncClientBuilder (org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder)1 PoolingAsyncClientConnectionManagerBuilder (org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder)1 ClientTlsStrategyBuilder (org.apache.hc.client5.http.ssl.ClientTlsStrategyBuilder)1 BasicHeader (org.apache.hc.core5.http.message.BasicHeader)1