@@ -243,25 +243,24 @@ private <RequestT, ResponseT, ErrorT> TransportHttpClient.Request prepareTranspo
243243 Map <String , String > params = endpoint .queryParameters (request );
244244
245245 List <ByteBuffer > bodyBuffers = null ;
246- HeaderMap headers = DefaultHeaders ;
246+ // Setting the Content-type header for all requests, even the ones without body.
247+ // This is a workaround for a bug with server version 9.1.2 and http2, where
248+ // http2 stream requests are considered not to have a body. So if the client doesn't always send
249+ // the Content-type header, empty body requests will fail with the above-described conditions.
250+ HeaderMap headers = JsonContentTypeHeaders ;
247251
248252 Object body = endpoint .body (request );
249253 if (body != null ) {
250254 // Request has a body
251255 if (body instanceof NdJsonpSerializable ) {
252256 bodyBuffers = new ArrayList <>();
253257 collectNdJsonLines (bodyBuffers , (NdJsonpSerializable ) request );
254- headers = JsonContentTypeHeaders ;
255-
256258 } else if (body instanceof BinaryData ) {
257259 BinaryData data = (BinaryData ) body ;
258260
259261 // ES expects the Accept and Content-Type headers to be consistent.
260262 String dataContentType = data .contentType ();
261- if (ContentType .APPLICATION_JSON .equals (dataContentType )) {
262- // Fast path
263- headers = JsonContentTypeHeaders ;
264- } else {
263+ if (!ContentType .APPLICATION_JSON .equals (dataContentType )) {
265264 headers = new HeaderMap (DefaultHeaders );
266265 headers .put (HeaderMap .CONTENT_TYPE , dataContentType );
267266 }
0 commit comments