From c45caf5b49517fc4c80bbbe1b85504736e1337a6 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Tue, 10 Dec 2024 08:20:09 -0500 Subject: [PATCH] Use the Upgrade flow by default Signed-off-by: Andriy Redko --- client/rest/licenses/httpclient5-5.4.1.jar.sha1 | 2 +- client/rest/licenses/httpcore5-5.3.1.jar.sha1 | 2 +- client/rest/licenses/httpcore5-h2-5.3.1.jar.sha1 | 2 +- client/rest/licenses/httpcore5-reactive-5.3.1.jar.sha1 | 2 +- .../java/org/opensearch/client/RestClientBuilder.java | 7 +------ .../client/RestClientSingleHostIntegTests.java | 10 +++++++++- client/sniffer/licenses/httpclient5-5.4.1.jar.sha1 | 2 +- client/sniffer/licenses/httpcore5-5.3.1.jar.sha1 | 2 +- 8 files changed, 16 insertions(+), 13 deletions(-) diff --git a/client/rest/licenses/httpclient5-5.4.1.jar.sha1 b/client/rest/licenses/httpclient5-5.4.1.jar.sha1 index 3a4fec6e8afc7..40156e9a42620 100644 --- a/client/rest/licenses/httpclient5-5.4.1.jar.sha1 +++ b/client/rest/licenses/httpclient5-5.4.1.jar.sha1 @@ -1 +1 @@ -ce913081e592ee8eeee35c4e577d7dce13cba7a4 +ce913081e592ee8eeee35c4e577d7dce13cba7a4 \ No newline at end of file diff --git a/client/rest/licenses/httpcore5-5.3.1.jar.sha1 b/client/rest/licenses/httpcore5-5.3.1.jar.sha1 index 90f194e770368..3b7536d6e8998 100644 --- a/client/rest/licenses/httpcore5-5.3.1.jar.sha1 +++ b/client/rest/licenses/httpcore5-5.3.1.jar.sha1 @@ -1 +1 @@ -eaf64237945d7d0f301d48420e8bdb7f565a7b0e +eaf64237945d7d0f301d48420e8bdb7f565a7b0e \ No newline at end of file diff --git a/client/rest/licenses/httpcore5-h2-5.3.1.jar.sha1 b/client/rest/licenses/httpcore5-h2-5.3.1.jar.sha1 index bc122991af736..6c3e4ffa5c6da 100644 --- a/client/rest/licenses/httpcore5-h2-5.3.1.jar.sha1 +++ b/client/rest/licenses/httpcore5-h2-5.3.1.jar.sha1 @@ -1 +1 @@ -760c34db3ba41b0ffa07e956bc308d3a12356915 +760c34db3ba41b0ffa07e956bc308d3a12356915 \ No newline at end of file diff --git a/client/rest/licenses/httpcore5-reactive-5.3.1.jar.sha1 b/client/rest/licenses/httpcore5-reactive-5.3.1.jar.sha1 index cb71833aad877..ca9828394f40e 100644 --- a/client/rest/licenses/httpcore5-reactive-5.3.1.jar.sha1 +++ b/client/rest/licenses/httpcore5-reactive-5.3.1.jar.sha1 @@ -1 +1 @@ -c4c0c3c7bbcb0db54aa7ddd39e34a835428c99c0 +c4c0c3c7bbcb0db54aa7ddd39e34a835428c99c0 \ No newline at end of file diff --git a/client/rest/src/main/java/org/opensearch/client/RestClientBuilder.java b/client/rest/src/main/java/org/opensearch/client/RestClientBuilder.java index 78a1d3e3fcf06..e5e23bbbd8226 100644 --- a/client/rest/src/main/java/org/opensearch/client/RestClientBuilder.java +++ b/client/rest/src/main/java/org/opensearch/client/RestClientBuilder.java @@ -308,16 +308,11 @@ 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)) - .setProtocolUpgradeEnabled(false); + .setResponseTimeout(Timeout.ofMilliseconds(DEFAULT_RESPONSE_TIMEOUT_MILLIS)); if (requestConfigCallback != null) { requestConfigBuilder = requestConfigCallback.customizeRequestConfig(requestConfigBuilder); } RequestConfig requestConfig = requestConfigBuilder.build(); - if (requestConfig.isProtocolUpgradeEnabled()) { - throw new IllegalArgumentException("protocol upgrade is not supported"); - } - try { final TlsStrategy tlsStrategy = ClientTlsStrategyBuilder.create() .setSslContext(SSLContext.getDefault()) diff --git a/client/rest/src/test/java/org/opensearch/client/RestClientSingleHostIntegTests.java b/client/rest/src/test/java/org/opensearch/client/RestClientSingleHostIntegTests.java index de04dd843b2db..84f6e7c8beb2e 100644 --- a/client/rest/src/test/java/org/opensearch/client/RestClientSingleHostIntegTests.java +++ b/client/rest/src/test/java/org/opensearch/client/RestClientSingleHostIntegTests.java @@ -382,6 +382,10 @@ public void testHeaders() throws Exception { if (method.equals("HEAD") == false) { standardHeaders.add("Content-length"); } + if (method.equals("HEAD") == true || method.equals("GET") == true || method.equals("OPTIONS") == true) { + standardHeaders.add("Upgrade"); + } + final Header[] requestHeaders = RestClientTestUtil.randomHeaders(getRandom(), "Header"); final int statusCode = randomStatusCode(getRandom()); Request request = new Request(method, "/" + statusCode); @@ -400,11 +404,15 @@ public void testHeaders() throws Exception { assertEquals(method, esResponse.getRequestLine().getMethod()); assertEquals(statusCode, esResponse.getStatusLine().getStatusCode()); assertEquals(pathPrefix + "/" + statusCode, esResponse.getRequestLine().getUri()); + assertHeaders(defaultHeaders, requestHeaders, esResponse.getHeaders(), standardHeaders); + final Set removedHeaders = new HashSet<>(); for (final Header responseHeader : esResponse.getHeaders()) { String name = responseHeader.getName(); - if (name.startsWith("Header") == false) { + // Some headers could be returned multiple times in response, like Connection fe. + if (name.startsWith("Header") == false && removedHeaders.contains(name) == false) { assertTrue("unknown header was returned " + name, standardHeaders.remove(name)); + removedHeaders.add(name); } } assertTrue("some expected standard headers weren't returned: " + standardHeaders, standardHeaders.isEmpty()); diff --git a/client/sniffer/licenses/httpclient5-5.4.1.jar.sha1 b/client/sniffer/licenses/httpclient5-5.4.1.jar.sha1 index 3a4fec6e8afc7..40156e9a42620 100644 --- a/client/sniffer/licenses/httpclient5-5.4.1.jar.sha1 +++ b/client/sniffer/licenses/httpclient5-5.4.1.jar.sha1 @@ -1 +1 @@ -ce913081e592ee8eeee35c4e577d7dce13cba7a4 +ce913081e592ee8eeee35c4e577d7dce13cba7a4 \ No newline at end of file diff --git a/client/sniffer/licenses/httpcore5-5.3.1.jar.sha1 b/client/sniffer/licenses/httpcore5-5.3.1.jar.sha1 index 90f194e770368..3b7536d6e8998 100644 --- a/client/sniffer/licenses/httpcore5-5.3.1.jar.sha1 +++ b/client/sniffer/licenses/httpcore5-5.3.1.jar.sha1 @@ -1 +1 @@ -eaf64237945d7d0f301d48420e8bdb7f565a7b0e +eaf64237945d7d0f301d48420e8bdb7f565a7b0e \ No newline at end of file