Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.hc.client5.http.ConfigDefaults;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
import org.apache.hc.client5.testing.classic.RandomHandler;
Expand Down Expand Up @@ -386,7 +386,7 @@ void testMixedTcpAndUdsConnectionPooling() throws Exception {
final URI requestUri = new URI("/random/2000");
final HttpGet udsRequest = new HttpGet(requestUri);
final HttpGet tcpRequest = new HttpGet(requestUri);
tcpRequest.setConfig(RequestConfig.DEFAULT);
tcpRequest.setConfig(ConfigDefaults.REQUEST);

final HttpClientResponseHandler<Object> consumer = response -> {
EntityUtils.consume(response.getEntity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import java.util.concurrent.ThreadFactory;

import org.apache.hc.client5.http.ConfigDefaults;
import org.apache.hc.client5.http.impl.DefaultClientConnectionReuseStrategy;
import org.apache.hc.client5.http.websocket.api.WebSocketClientConfig;
import org.apache.hc.client5.http.websocket.client.impl.DefaultWebSocketClient;
Expand Down Expand Up @@ -432,15 +433,15 @@ public CloseableWebSocketClient build() {

final HttpProcessor proc = httpProcessor != null ? httpProcessor : HttpProcessors.client();
final Http1Config h1 = http1Config != null ? http1Config : Http1Config.DEFAULT;
final CharCodingConfig coding = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
final CharCodingConfig coding = charCodingConfig != null ? charCodingConfig : ConfigDefaults.CHAR_CODING;
final ConnectionReuseStrategy reuseStrategyCopy = connStrategy != null ? connStrategy : new DefaultClientConnectionReuseStrategy();

final TlsStrategy tls = tlsStrategy != null ? tlsStrategy : new BasicClientTlsStrategy();

final IOReactorMetricsListener metricsListener = reactorMetricsListener != null ? reactorMetricsListener : null;

final HttpAsyncRequester requester = AsyncRequesterBootstrap.bootstrap()
.setIOReactorConfig(ioReactorConfig != null ? ioReactorConfig : IOReactorConfig.DEFAULT)
.setIOReactorConfig(ioReactorConfig != null ? ioReactorConfig : ConfigDefaults.IO_REACTOR)
.setHttpProcessor(proc)
.setHttp1Config(h1)
.setCharCodingConfig(coding)
Expand All @@ -462,7 +463,7 @@ public CloseableWebSocketClient build() {
.create();

final H2MultiplexingRequester h2Requester = H2MultiplexingRequesterBootstrap.bootstrap()
.setIOReactorConfig(ioReactorConfig != null ? ioReactorConfig : IOReactorConfig.DEFAULT)
.setIOReactorConfig(ioReactorConfig != null ? ioReactorConfig : ConfigDefaults.IO_REACTOR)
.setHttpProcessor(h2HttpProcessor != null ? h2HttpProcessor : H2Processors.client())
.setH2Config(h2Config != null ? h2Config : H2Config.DEFAULT)
.setTlsStrategy(tls)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import javax.net.ssl.SSLSocket;

import org.apache.hc.client5.http.ConfigDefaults;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.ContentLengthStrategy;
Expand Down Expand Up @@ -64,7 +65,7 @@ class WebSocketServerConnectionFactory implements HttpConnectionFactory<WebSocke
final HttpMessageWriterFactory<ClassicHttpResponse> responseWriterFactory) {
this.scheme = scheme;
this.http1Config = http1Config != null ? http1Config : Http1Config.DEFAULT;
this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
this.charCodingConfig = charCodingConfig != null ? charCodingConfig : ConfigDefaults.CHAR_CODING;
this.incomingContentStrategy = incomingContentStrategy;
this.outgoingContentStrategy = outgoingContentStrategy;
this.requestParserFactory = requestParserFactory != null ? requestParserFactory :
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.hc.client5.http;

import org.apache.hc.client5.http.config.ConnectionConfig;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.config.TlsConfig;
import org.apache.hc.core5.annotation.Internal;
import org.apache.hc.core5.http.config.CharCodingConfig;
import org.apache.hc.core5.http.config.Http1Config;
import org.apache.hc.core5.http.io.SocketConfig;
import org.apache.hc.core5.http2.config.H2Config;
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.core5.util.Timeout;

/**
* @since 5.7
*/
@Internal
final public class ConfigDefaults {

private static final Timeout DEFAULT_SOCKET_TIMEOUT = Timeout.ofMinutes(3);

public static final IOReactorConfig IO_REACTOR = IOReactorConfig.custom()
.setSoTimeout(DEFAULT_SOCKET_TIMEOUT)
.build();

public static final SocketConfig SOCKET = SocketConfig.custom()
.setSoTimeout(DEFAULT_SOCKET_TIMEOUT)
.build();

public static final CharCodingConfig CHAR_CODING = CharCodingConfig.DEFAULT;
public static final H2Config H2 = H2Config.DEFAULT;
public static final Http1Config HTTP1 = Http1Config.DEFAULT;
public static final ConnectionConfig CONNECTION = ConnectionConfig.DEFAULT;
public static final TlsConfig TLS = TlsConfig.DEFAULT;
public static final RequestConfig REQUEST = RequestConfig.DEFAULT;

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.concurrent.ThreadFactory;

import org.apache.hc.client5.http.AuthenticationStrategy;
import org.apache.hc.client5.http.ConfigDefaults;
import org.apache.hc.client5.http.DnsResolver;
import org.apache.hc.client5.http.HttpRequestRetryStrategy;
import org.apache.hc.client5.http.SchemePortResolver;
Expand Down Expand Up @@ -922,12 +923,12 @@ public CloseableHttpAsyncClient build() {
final IOEventHandlerFactory ioEventHandlerFactory = new H2AsyncClientProtocolStarter(
HttpProcessorBuilder.create().build(),
(request, context) -> pushConsumerRegistry.get(request),
h2Config != null ? h2Config : H2Config.DEFAULT,
charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT,
h2Config != null ? h2Config : ConfigDefaults.H2,
charCodingConfig != null ? charCodingConfig : ConfigDefaults.CHAR_CODING,
ioReactorExceptionCallback != null ? ioReactorExceptionCallback : LoggingExceptionCallback.INSTANCE);
final DefaultConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(
ioEventHandlerFactory,
ioReactorConfig != null ? ioReactorConfig : IOReactorConfig.DEFAULT,
ioReactorConfig != null ? ioReactorConfig : ConfigDefaults.IO_REACTOR,
threadFactory != null ? threadFactory : new DefaultThreadFactory("httpclient-dispatch", true),
ioSessionDecorator != null ? ioSessionDecorator : LoggingIOSessionDecorator.INSTANCE,
ioReactorExceptionCallback != null ? ioReactorExceptionCallback : LoggingExceptionCallback.INSTANCE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.IOException;
import java.util.List;

import org.apache.hc.client5.http.ConfigDefaults;
import org.apache.hc.core5.function.Callback;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpConnection;
Expand Down Expand Up @@ -71,8 +72,8 @@ class H2AsyncClientProtocolStarter implements IOEventHandlerFactory {
final Callback<Exception> exceptionCallback) {
this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
this.exchangeHandlerFactory = exchangeHandlerFactory;
this.h2Config = h2Config != null ? h2Config : H2Config.DEFAULT;
this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
this.h2Config = h2Config != null ? h2Config : ConfigDefaults.H2;
this.charCodingConfig = charCodingConfig != null ? charCodingConfig : ConfigDefaults.CHAR_CODING;
this.exceptionCallback = exceptionCallback;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.function.UnaryOperator;

import org.apache.hc.client5.http.AuthenticationStrategy;
import org.apache.hc.client5.http.ConfigDefaults;
import org.apache.hc.client5.http.ConnectionKeepAliveStrategy;
import org.apache.hc.client5.http.EarlyHintsListener;
import org.apache.hc.client5.http.HttpRequestRetryStrategy;
Expand Down Expand Up @@ -1209,14 +1210,14 @@ public CloseableHttpAsyncClient build() {
final IOEventHandlerFactory ioEventHandlerFactory = new HttpAsyncClientProtocolNegotiationStarter(
HttpProcessorBuilder.create().build(),
(request, context) -> pushConsumerRegistry.get(request),
h2Config != null ? h2Config : H2Config.DEFAULT,
h1Config != null ? h1Config : Http1Config.DEFAULT,
charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT,
h2Config != null ? h2Config : ConfigDefaults.H2,
h1Config != null ? h1Config : ConfigDefaults.HTTP1,
charCodingConfig != null ? charCodingConfig : ConfigDefaults.CHAR_CODING,
reuseStrategyCopy,
ioReactorExceptionCallback != null ? ioReactorExceptionCallback : LoggingExceptionCallback.INSTANCE);
final DefaultConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(
ioEventHandlerFactory,
ioReactorConfig != null ? ioReactorConfig : IOReactorConfig.DEFAULT,
ioReactorConfig != null ? ioReactorConfig : ConfigDefaults.IO_REACTOR,
threadFactory != null ? threadFactory : new DefaultThreadFactory("httpclient-dispatch", true),
ioSessionDecorator != null ? ioSessionDecorator : LoggingIOSessionDecorator.INSTANCE,
ioReactorExceptionCallback != null ? ioReactorExceptionCallback : LoggingExceptionCallback.INSTANCE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Iterator;
import java.util.List;

import org.apache.hc.client5.http.ConfigDefaults;
import org.apache.hc.client5.http.impl.DefaultClientConnectionReuseStrategy;
import org.apache.hc.core5.function.Callback;
import org.apache.hc.core5.http.ConnectionReuseStrategy;
Expand Down Expand Up @@ -98,9 +99,9 @@ class HttpAsyncClientProtocolNegotiationStarter implements IOEventHandlerFactory
final Callback<Exception> exceptionCallback) {
this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
this.exchangeHandlerFactory = exchangeHandlerFactory;
this.h2Config = h2Config != null ? h2Config : H2Config.DEFAULT;
this.h1Config = h1Config != null ? h1Config : Http1Config.DEFAULT;
this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
this.h2Config = h2Config != null ? h2Config : ConfigDefaults.H2;
this.h1Config = h1Config != null ? h1Config : ConfigDefaults.HTTP1;
this.charCodingConfig = charCodingConfig != null ? charCodingConfig : ConfigDefaults.CHAR_CODING;
this.http1ConnectionReuseStrategy = connectionReuseStrategy != null ? connectionReuseStrategy : DefaultClientConnectionReuseStrategy.INSTANCE;
this.http1ResponseParserFactory = new DefaultHttpResponseParserFactory(h1Config);
this.http1RequestWriterFactory = DefaultHttpRequestWriterFactory.INSTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

package org.apache.hc.client5.http.impl.async;

import org.apache.hc.client5.http.ConfigDefaults;
import org.apache.hc.client5.http.DnsResolver;
import org.apache.hc.client5.http.SchemePortResolver;
import org.apache.hc.client5.http.SystemDefaultDnsResolver;
Expand All @@ -41,7 +42,6 @@
import org.apache.hc.core5.annotation.Experimental;
import org.apache.hc.core5.concurrent.DefaultThreadFactory;
import org.apache.hc.core5.function.Supplier;
import org.apache.hc.core5.http.config.CharCodingConfig;
import org.apache.hc.core5.http.config.Http1Config;
import org.apache.hc.core5.http.impl.routing.RequestRouter;
import org.apache.hc.core5.http.nio.AsyncPushConsumer;
Expand Down Expand Up @@ -172,7 +172,7 @@ public static MinimalHttpAsyncClient createMinimal(
(request, context) -> pushConsumerRegistry.get(request),
h2Config,
h1Config,
CharCodingConfig.DEFAULT,
ConfigDefaults.CHAR_CODING,
DefaultClientConnectionReuseStrategy.INSTANCE,
LoggingExceptionCallback.INSTANCE),
pushConsumerRegistry,
Expand Down Expand Up @@ -201,7 +201,7 @@ public static MinimalHttpAsyncClient createMinimal(
(request, context) -> pushConsumerRegistry.get(request),
h2Config,
h1Config,
CharCodingConfig.DEFAULT,
ConfigDefaults.CHAR_CODING,
DefaultClientConnectionReuseStrategy.INSTANCE,
LoggingExceptionCallback.INSTANCE),
pushConsumerRegistry,
Expand Down Expand Up @@ -247,7 +247,7 @@ public static MinimalHttpAsyncClient createMinimal(
* functionality.
*/
public static MinimalHttpAsyncClient createMinimal(final H2Config h2Config, final Http1Config h1Config) {
return createMinimal(HttpVersionPolicy.NEGOTIATE, h2Config, h1Config, IOReactorConfig.DEFAULT);
return createMinimal(HttpVersionPolicy.NEGOTIATE, h2Config, h1Config, ConfigDefaults.IO_REACTOR);
}

/**
Expand All @@ -256,7 +256,7 @@ public static MinimalHttpAsyncClient createMinimal(final H2Config h2Config, fina
* functionality.
*/
public static MinimalHttpAsyncClient createMinimal() {
return createMinimal(H2Config.DEFAULT, Http1Config.DEFAULT);
return createMinimal(ConfigDefaults.H2, ConfigDefaults.HTTP1);
}

/**
Expand All @@ -267,9 +267,9 @@ public static MinimalHttpAsyncClient createMinimal() {
public static MinimalHttpAsyncClient createMinimal(final AsyncClientConnectionManager connManager) {
return createMinimal(
HttpVersionPolicy.NEGOTIATE,
H2Config.DEFAULT,
Http1Config.DEFAULT,
IOReactorConfig.DEFAULT,
ConfigDefaults.H2,
ConfigDefaults.HTTP1,
ConfigDefaults.IO_REACTOR,
connManager);
}

Expand Down Expand Up @@ -304,7 +304,7 @@ public static MinimalH2AsyncClient createHttp2Minimal(
createMinimalProtocolProcessor(),
(request, context) -> pushConsumerRegistry.get(request),
h2Config,
CharCodingConfig.DEFAULT,
ConfigDefaults.CHAR_CODING,
LoggingExceptionCallback.INSTANCE),
pushConsumerRegistry,
ioReactorConfig,
Expand Down Expand Up @@ -338,15 +338,15 @@ public static MinimalH2AsyncClient createHttp2Minimal(
* transport without advanced HTTP protocol functionality.
*/
public static MinimalH2AsyncClient createHttp2Minimal(final H2Config h2Config) {
return createHttp2Minimal(h2Config, IOReactorConfig.DEFAULT);
return createHttp2Minimal(h2Config, ConfigDefaults.IO_REACTOR);
}

/**
* Creates {@link MinimalH2AsyncClient} instance optimized for HTTP/2 multiplexing message
* transport without advanced HTTP protocol functionality.
*/
public static MinimalH2AsyncClient createHttp2Minimal() {
return createHttp2Minimal(H2Config.DEFAULT);
return createHttp2Minimal(ConfigDefaults.H2);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.time.Clock;
import java.util.concurrent.Future;

import org.apache.hc.client5.http.ConfigDefaults;
import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.config.ConnectionConfig;
import org.apache.hc.core5.concurrent.CallbackContribution;
Expand Down Expand Up @@ -198,7 +199,7 @@ ConnectionConfig resolveConnectionConfig(final HttpRoute route) {
final HttpHost target = route.getTargetHost();
final Resolver<HttpHost, ConnectionConfig> localResolver = connectionConfigResolver;
final ConnectionConfig connectionConfig = localResolver != null ? localResolver.resolve(target) : null;
return connectionConfig != null ? connectionConfig : ConnectionConfig.DEFAULT;
return connectionConfig != null ? connectionConfig : ConfigDefaults.CONNECTION;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.function.UnaryOperator;

import org.apache.hc.client5.http.AuthenticationStrategy;
import org.apache.hc.client5.http.ConfigDefaults;
import org.apache.hc.client5.http.ConnectionKeepAliveStrategy;
import org.apache.hc.client5.http.HttpRequestRetryStrategy;
import org.apache.hc.client5.http.SchemePortResolver;
Expand Down Expand Up @@ -1132,7 +1133,7 @@ public CloseableHttpClient build() {
defaultCookieStore,
defaultCredentialsProvider,
contextAdaptor(),
defaultRequestConfig != null ? defaultRequestConfig : RequestConfig.DEFAULT,
defaultRequestConfig != null ? defaultRequestConfig : ConfigDefaults.REQUEST,
closeablesCopy);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.net.Socket;

import org.apache.hc.client5.http.AuthenticationStrategy;
import org.apache.hc.client5.http.ConfigDefaults;
import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.RouteInfo.LayerType;
import org.apache.hc.client5.http.RouteInfo.TunnelType;
Expand Down Expand Up @@ -105,7 +106,7 @@ public ProxyClient(
.http1Config(h1Config)
.charCodingConfig(charCodingConfig)
.build();
this.requestConfig = requestConfig != null ? requestConfig : RequestConfig.DEFAULT;
this.requestConfig = requestConfig != null ? requestConfig : ConfigDefaults.REQUEST;
this.httpProcessor = new DefaultHttpProcessor(
new RequestTargetHost(), new RequestClientConnControl(), new RequestUserAgent());
this.requestExec = new HttpRequestExecutor();
Expand Down
Loading
Loading