Skip to content

Commit f63b0a2

Browse files
committed
upgrade httpcore5/httpclient5 to support ExtendedSocketOption in HttpAsyncClient
Signed-off-by: kkewwei <kewei.11@bytedance.com> Signed-off-by: kkewwei <kkewwei@163.com>
1 parent b75f27a commit f63b0a2

18 files changed

+47
-12
lines changed

CHANGELOG-3.0.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1515
- Views, simplify data access and manipulation by providing a virtual layer over one or more indices ([#11957](https://github.com/opensearch-project/OpenSearch/pull/11957))
1616

1717
### Dependencies
18+
- Bump Apache HttpCore5/HttpClient5 dependencies from 5.2.5/5.3.1 to 5.3.1/5.4.1 to support ExtendedSocketOption in HttpAsyncClient ([#16757](https://github.com/opensearch-project/OpenSearch/pull/16757))
1819

1920
### Changed
2021
- Changed locale provider from COMPAT to CLDR ([#14345](https://github.com/opensearch-project/OpenSearch/pull/14345))

client/rest/licenses/httpclient5-5.3.1.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ce913081e592ee8eeee35c4e577d7dce13cba7a4

client/rest/licenses/httpcore5-5.2.5.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
eaf64237945d7d0f301d48420e8bdb7f565a7b0e

client/rest/licenses/httpcore5-h2-5.2.5.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
760c34db3ba41b0ffa07e956bc308d3a12356915

client/rest/licenses/httpcore5-reactive-5.2.5.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c4c0c3c7bbcb0db54aa7ddd39e34a835428c99c0

client/rest/src/main/java/org/opensearch/client/RestClientBuilder.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,15 @@ private CloseableHttpAsyncClient createHttpClient() {
308308
// default timeouts are all infinite
309309
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom()
310310
.setConnectTimeout(Timeout.ofMilliseconds(DEFAULT_CONNECT_TIMEOUT_MILLIS))
311-
.setResponseTimeout(Timeout.ofMilliseconds(DEFAULT_RESPONSE_TIMEOUT_MILLIS));
311+
.setResponseTimeout(Timeout.ofMilliseconds(DEFAULT_RESPONSE_TIMEOUT_MILLIS))
312+
.setProtocolUpgradeEnabled(false);
312313
if (requestConfigCallback != null) {
313314
requestConfigBuilder = requestConfigCallback.customizeRequestConfig(requestConfigBuilder);
314315
}
316+
RequestConfig requestConfig = requestConfigBuilder.build();
317+
if (requestConfig.isProtocolUpgradeEnabled()) {
318+
throw new IllegalArgumentException("protocol upgrade is not supported");
319+
}
315320

316321
try {
317322
final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder.create()
@@ -332,7 +337,7 @@ public TlsDetails create(final SSLEngine sslEngine) {
332337
.build();
333338

334339
HttpAsyncClientBuilder httpClientBuilder = HttpAsyncClientBuilder.create()
335-
.setDefaultRequestConfig(requestConfigBuilder.build())
340+
.setDefaultRequestConfig(requestConfig)
336341
.setConnectionManager(connectionManager)
337342
.setTargetAuthenticationStrategy(DefaultAuthenticationStrategy.INSTANCE)
338343
.disableAutomaticRetries();

client/rest/src/test/java/org/opensearch/client/RestClientBuilderTests.java

+7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.hc.core5.http.Header;
3838
import org.apache.hc.core5.http.HttpHost;
3939
import org.apache.hc.core5.http.message.BasicHeader;
40+
import org.apache.hc.core5.reactor.IOReactorConfig;
4041
import org.apache.hc.core5.util.Timeout;
4142

4243
import java.io.IOException;
@@ -143,6 +144,12 @@ public void testBuild() throws IOException {
143144
builder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
144145
@Override
145146
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
147+
IOReactorConfig.Builder iOReactorConfig = IOReactorConfig.custom();
148+
iOReactorConfig.setTcpKeepCount(randomIntBetween(4, 10));
149+
iOReactorConfig.setTcpKeepInterval(randomIntBetween(5, 10));
150+
iOReactorConfig.setTcpKeepIdle(randomIntBetween(100, 200));
151+
iOReactorConfig.setIoThreadCount(2);
152+
httpClientBuilder.setIOReactorConfig(iOReactorConfig.build());
146153
return httpClientBuilder;
147154
}
148155
});

client/rest/src/test/java/org/opensearch/client/documentation/RestClientDocumentation.java

+18
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,24 @@ public HttpAsyncClientBuilder customizeHttpClient(
376376
});
377377
//end::rest-client-config-threads
378378
}
379+
{
380+
//tag::rest-client-config-tcpKeepIdle/tcpKeepInterval/tcpKeepCount
381+
RestClientBuilder builder = RestClient.builder(
382+
new HttpHost("localhost", 9200))
383+
.setHttpClientConfigCallback(new HttpClientConfigCallback() {
384+
@Override
385+
public HttpAsyncClientBuilder customizeHttpClient(
386+
HttpAsyncClientBuilder httpClientBuilder) {
387+
return httpClientBuilder.setIOReactorConfig(
388+
IOReactorConfig.custom()
389+
.setTcpKeepIdle(200)
390+
.setTcpKeepInterval(10)
391+
.setTcpKeepCount(10)
392+
.build());
393+
}
394+
});
395+
//end::rest-client-config-tcpKeepIdle/tcpKeepInterval/tcpKeepCount
396+
}
379397
{
380398
//tag::rest-client-config-basic-auth
381399
final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();

client/sniffer/licenses/httpclient5-5.3.1.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ce913081e592ee8eeee35c4e577d7dce13cba7a4

client/sniffer/licenses/httpcore5-5.2.5.jar.sha1

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
eaf64237945d7d0f301d48420e8bdb7f565a7b0e

gradle/libs.versions.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ reactor_netty = "1.1.23"
4040
reactor = "3.5.20"
4141

4242
# client dependencies
43-
httpclient5 = "5.3.1"
44-
httpcore5 = "5.2.5"
43+
httpclient5 = "5.4.1"
44+
httpcore5 = "5.3.1"
4545
httpclient = "4.5.14"
4646
httpcore = "4.4.16"
4747
httpasyncclient = "4.1.5"

test/framework/src/main/java/org/opensearch/bootstrap/BootstrapForTesting.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,15 @@ static Set<URL> parseClassPathWithSymlinks() throws Exception {
301301
private static Set<String> getTrustedHosts() {
302302
//
303303
try {
304-
return Collections.list(NetworkInterface.getNetworkInterfaces())
304+
List<String> hosts = Collections.list(NetworkInterface.getNetworkInterfaces())
305305
.stream()
306306
.flatMap(iface -> Collections.list(iface.getInetAddresses()).stream())
307307
.map(address -> NetworkAddress.format(address))
308-
.collect(Collectors.toSet());
308+
.collect(Collectors.toList());
309+
// 0:0:0:0:0:0:0:1 is simplified to ::1, in it test, the incoming address can be 0:0:0:0:0:0:0:1,
310+
// so we should add it to trusted hosts.
311+
hosts.add("0:0:0:0:0:0:0:1");
312+
return Collections.unmodifiableSet(new HashSet<>(hosts));
309313
} catch (final SocketException e) {
310314
return Collections.emptySet();
311315
}

0 commit comments

Comments
 (0)