diff --git a/java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransportBase.java b/java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransportBase.java index 8d561f506..26dcd273b 100644 --- a/java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransportBase.java +++ b/java-client/src/main/java/co/elastic/clients/transport/ElasticsearchTransportBase.java @@ -243,7 +243,11 @@ private TransportHttpClient.Request prepareTranspo Map params = endpoint.queryParameters(request); List bodyBuffers = null; - HeaderMap headers = DefaultHeaders; + // Setting the Content-type header for all requests, even the ones without body. + // This is a workaround for a bug with server version 9.1.2 and http2, where + // http2 stream requests are considered not to have a body. So if the client doesn't always send + // the Content-type header, empty body requests will fail with the above-described conditions. + HeaderMap headers = JsonContentTypeHeaders; Object body = endpoint.body(request); if (body != null) { @@ -251,17 +255,12 @@ private TransportHttpClient.Request prepareTranspo if (body instanceof NdJsonpSerializable) { bodyBuffers = new ArrayList<>(); collectNdJsonLines(bodyBuffers, (NdJsonpSerializable) request); - headers = JsonContentTypeHeaders; - } else if (body instanceof BinaryData) { BinaryData data = (BinaryData) body; // ES expects the Accept and Content-Type headers to be consistent. String dataContentType = data.contentType(); - if (ContentType.APPLICATION_JSON.equals(dataContentType)) { - // Fast path - headers = JsonContentTypeHeaders; - } else { + if (!ContentType.APPLICATION_JSON.equals(dataContentType)) { headers = new HeaderMap(DefaultHeaders); headers.put(HeaderMap.CONTENT_TYPE, dataContentType); } diff --git a/java-client/src/main/java/co/elastic/clients/transport/rest5_client/Rest5ClientOptions.java b/java-client/src/main/java/co/elastic/clients/transport/rest5_client/Rest5ClientOptions.java index 6135a6738..2520b16bb 100644 --- a/java-client/src/main/java/co/elastic/clients/transport/rest5_client/Rest5ClientOptions.java +++ b/java-client/src/main/java/co/elastic/clients/transport/rest5_client/Rest5ClientOptions.java @@ -238,7 +238,7 @@ private static String getClientMeta() { VersionInfo httpClientVersion = null; try { httpClientVersion = VersionInfo.loadVersionInfo( - "org.apache.http.nio.client", + "org.apache.hc.core5", HttpAsyncClientBuilder.class.getClassLoader() ); } catch (Exception e) { diff --git a/java-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/BufferedByteConsumer.java b/java-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/BufferedByteConsumer.java index ef33c7295..f42bb413e 100644 --- a/java-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/BufferedByteConsumer.java +++ b/java-client/src/main/java/co/elastic/clients/transport/rest5_client/low_level/BufferedByteConsumer.java @@ -57,7 +57,7 @@ protected int capacityIncrement() { protected void data(final ByteBuffer src, final boolean endOfStream) throws ContentTooLongException { if (buffer.length() + src.limit() > limit) { throw new ContentTooLongException( - "entity content is too long [" + src.capacity() + "] for the configured buffer limit [" + limit + "]" + "entity content is too long [" + src.limit() + "] for the configured buffer limit [" + limit + "]" ); } buffer.append(src);