Search in sources :

Example 6 with BasicHeader

use of org.apache.hc.core5.http.message.BasicHeader 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

BasicHeader (org.apache.hc.core5.http.message.BasicHeader)6 SimpleHttpResponse (org.apache.hc.client5.http.async.methods.SimpleHttpResponse)2 HttpPost (org.apache.hc.client5.http.classic.methods.HttpPost)2 RequestConfig (org.apache.hc.client5.http.config.RequestConfig)2 UrlEncodedFormEntity (org.apache.hc.client5.http.entity.UrlEncodedFormEntity)2 HttpClientBuilder (org.apache.hc.client5.http.impl.classic.HttpClientBuilder)2 PoolingHttpClientConnectionManager (org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager)2 NameValuePair (org.apache.hc.core5.http.NameValuePair)2 BasicNameValuePair (org.apache.hc.core5.http.message.BasicNameValuePair)2 U (com.weicoder.common.U)1 W (com.weicoder.common.W)1 HttpConstants (com.weicoder.common.constants.HttpConstants)1 StringConstants (com.weicoder.common.constants.StringConstants)1 IOUtil (com.weicoder.common.io.IOUtil)1 Lists (com.weicoder.common.lang.Lists)1 Log (com.weicoder.common.log.Log)1 LogFactory (com.weicoder.common.log.LogFactory)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1