Skip to content

Commit

Permalink
upgrade httpcore5/httpclient5 to support ExtendedSocketOption in Http…
Browse files Browse the repository at this point in the history
…AsyncClient

Signed-off-by: kkewwei <[email protected]>
Signed-off-by: kkewwei <[email protected]>
  • Loading branch information
kkewwei committed Dec 3, 2024
1 parent b75f27a commit 1beba95
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- 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))

### Dependencies
- 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))

### Changed
- Changed locale provider from COMPAT to CLDR ([#14345](https://github.com/opensearch-project/OpenSearch/pull/14345))
Expand Down
1 change: 0 additions & 1 deletion client/rest/licenses/httpclient5-5.3.1.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions client/rest/licenses/httpclient5-5.4.1.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ce913081e592ee8eeee35c4e577d7dce13cba7a4
1 change: 0 additions & 1 deletion client/rest/licenses/httpcore5-5.2.5.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions client/rest/licenses/httpcore5-5.3.1.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eaf64237945d7d0f301d48420e8bdb7f565a7b0e
1 change: 0 additions & 1 deletion client/rest/licenses/httpcore5-h2-5.2.5.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions client/rest/licenses/httpcore5-h2-5.3.1.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
760c34db3ba41b0ffa07e956bc308d3a12356915
1 change: 0 additions & 1 deletion client/rest/licenses/httpcore5-reactive-5.2.5.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions client/rest/licenses/httpcore5-reactive-5.3.1.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c4c0c3c7bbcb0db54aa7ddd39e34a835428c99c0
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public final class RestClientBuilder {
*/
public static final int DEFAULT_MAX_CONN_TOTAL = 30;

/**
* The default value which determines whether the client server should automatically attempt to upgrade to a safer.
*/
public static final boolean DEFAULT_PROTOCOL_UPGRADE_ENABLED = false;

private static final Header[] EMPTY_HEADERS = new Header[0];

private final List<Node> nodes;
Expand Down Expand Up @@ -308,7 +313,8 @@ private CloseableHttpAsyncClient createHttpClient() {
// default timeouts are all infinite
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom()
.setConnectTimeout(Timeout.ofMilliseconds(DEFAULT_CONNECT_TIMEOUT_MILLIS))
.setResponseTimeout(Timeout.ofMilliseconds(DEFAULT_RESPONSE_TIMEOUT_MILLIS));
.setResponseTimeout(Timeout.ofMilliseconds(DEFAULT_RESPONSE_TIMEOUT_MILLIS))
.setProtocolUpgradeEnabled(DEFAULT_PROTOCOL_UPGRADE_ENABLED);
if (requestConfigCallback != null) {
requestConfigBuilder = requestConfigCallback.customizeRequestConfig(requestConfigBuilder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpHost;
import org.apache.hc.core5.http.message.BasicHeader;
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.core5.util.Timeout;

import java.io.IOException;
Expand Down Expand Up @@ -143,6 +144,12 @@ public void testBuild() throws IOException {
builder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
IOReactorConfig.Builder iOReactorConfig = IOReactorConfig.custom();
iOReactorConfig.setTcpKeepCount(randomIntBetween(4, 10));
iOReactorConfig.setTcpKeepInterval(randomIntBetween(5, 10));
iOReactorConfig.setTcpKeepIdle(randomIntBetween(100, 200));
iOReactorConfig.setIoThreadCount(2);
httpClientBuilder.setIOReactorConfig(iOReactorConfig.build());
return httpClientBuilder;
}
});
Expand All @@ -151,6 +158,10 @@ public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpCli
builder.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override
public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
if (randomBoolean()) {
// https://github.com/apache/httpcomponents-client/pull/542 support Upgrading to TLS Within HTTP/1.1
requestConfigBuilder.setProtocolUpgradeEnabled(true);
}
return requestConfigBuilder;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,37 @@ public HttpAsyncClientBuilder customizeHttpClient(
});
//end::rest-client-config-threads
}
{
//tag::rest-client-config-tcpKeepIdle/tcpKeepInterval/tcpKeepCount
RestClientBuilder builder = RestClient.builder(
new HttpHost("localhost", 9200))
.setHttpClientConfigCallback(new HttpClientConfigCallback() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(
HttpAsyncClientBuilder httpClientBuilder) {
return httpClientBuilder.setIOReactorConfig(
IOReactorConfig.custom()
.setTcpKeepIdle(200)
.setTcpKeepInterval(10)
.setTcpKeepCount(10)
.build());
}
});
//end::rest-client-config-tcpKeepIdle/tcpKeepInterval/tcpKeepCount
}
{
//tag::rest-client-config-protocolUpgradeEnabled
RestClientBuilder builder = RestClient.builder(
new HttpHost("localhost", 9200))
.setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override
public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) {
requestConfigBuilder.setProtocolUpgradeEnabled(true);
return requestConfigBuilder;
}
});
//end::rest-client-config-protocolUpgradeEnabled
}
{
//tag::rest-client-config-basic-auth
final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
Expand Down
1 change: 0 additions & 1 deletion client/sniffer/licenses/httpclient5-5.3.1.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions client/sniffer/licenses/httpclient5-5.4.1.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ce913081e592ee8eeee35c4e577d7dce13cba7a4
1 change: 0 additions & 1 deletion client/sniffer/licenses/httpcore5-5.2.5.jar.sha1

This file was deleted.

1 change: 1 addition & 0 deletions client/sniffer/licenses/httpcore5-5.3.1.jar.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eaf64237945d7d0f301d48420e8bdb7f565a7b0e
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ reactor_netty = "1.1.23"
reactor = "3.5.20"

# client dependencies
httpclient5 = "5.3.1"
httpcore5 = "5.2.5"
httpclient5 = "5.4.1"
httpcore5 = "5.3.1"
httpclient = "4.5.14"
httpcore = "4.4.16"
httpasyncclient = "4.1.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,15 @@ static Set<URL> parseClassPathWithSymlinks() throws Exception {
private static Set<String> getTrustedHosts() {
//
try {
return Collections.list(NetworkInterface.getNetworkInterfaces())
List<String> hosts = Collections.list(NetworkInterface.getNetworkInterfaces())
.stream()
.flatMap(iface -> Collections.list(iface.getInetAddresses()).stream())
.map(address -> NetworkAddress.format(address))
.collect(Collectors.toSet());
.collect(Collectors.toList());
// 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,
// so we should add it to trusted hosts.
hosts.add("0:0:0:0:0:0:0:1");
return Collections.unmodifiableSet(new HashSet<>(hosts));
} catch (final SocketException e) {
return Collections.emptySet();
}
Expand Down

0 comments on commit 1beba95

Please sign in to comment.