Skip to content
Merged
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 @@ -243,25 +243,24 @@ private <RequestT, ResponseT, ErrorT> TransportHttpClient.Request prepareTranspo
Map<String, String> params = endpoint.queryParameters(request);

List<ByteBuffer> 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a note here explaining why we set the content-type even for requests with no body. It will be useful for our future selves!


Object body = endpoint.body(request);
if (body != null) {
// Request has a body
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading