diff --git a/sdk/core/azure-core-http-jdk-httpclient/src/main/java/com/azure/core/http/jdk/httpclient/JdkAsyncHttpClient.java b/sdk/core/azure-core-http-jdk-httpclient/src/main/java/com/azure/core/http/jdk/httpclient/JdkAsyncHttpClient.java index 7b869646711db..bc91fe9a0cedb 100644 --- a/sdk/core/azure-core-http-jdk-httpclient/src/main/java/com/azure/core/http/jdk/httpclient/JdkAsyncHttpClient.java +++ b/sdk/core/azure-core-http-jdk-httpclient/src/main/java/com/azure/core/http/jdk/httpclient/JdkAsyncHttpClient.java @@ -96,8 +96,7 @@ private Mono toJdkHttpRequest(HttpRequest request) { for (HttpHeader header : headers) { final String headerName = header.getName(); if (!restrictedHeaders.contains(headerName)) { - final String headerValue = header.getValue(); - builder.setHeader(headerName, headerValue); + header.getValuesList().forEach(headerValue -> builder.header(headerName, headerValue)); } else { logger.warning("The header '" + headerName + "' is restricted by default in JDK HttpClient 12 " + "and above. This header can be added to allow list in JAVA_HOME/conf/net.properties " @@ -135,7 +134,7 @@ private static BodyPublisher toBodyPublisher(Flux bbPublisher, Strin } else { long contentLengthLong = Long.parseLong(contentLength); if (contentLengthLong < 1) { - return fromPublisher(bbFlowPublisher); + return noBody(); } else { return fromPublisher(bbFlowPublisher, contentLengthLong); } diff --git a/sdk/core/azure-core-http-jdk-httpclient/src/main/java/com/azure/core/http/jdk/httpclient/JdkHttpResponse.java b/sdk/core/azure-core-http-jdk-httpclient/src/main/java/com/azure/core/http/jdk/httpclient/JdkHttpResponse.java index 76d4a091d922e..290c04c2398cb 100644 --- a/sdk/core/azure-core-http-jdk-httpclient/src/main/java/com/azure/core/http/jdk/httpclient/JdkHttpResponse.java +++ b/sdk/core/azure-core-http-jdk-httpclient/src/main/java/com/azure/core/http/jdk/httpclient/JdkHttpResponse.java @@ -33,7 +33,11 @@ public Flux getBody() { @Override public Mono getBodyAsByteArray() { - return FluxUtil.collectBytesFromNetworkResponse(getBody(), getHeaders()); + return FluxUtil.collectBytesFromNetworkResponse(getBody(), getHeaders()) + // Map empty byte[] into Mono.empty, this matches how the other HttpResponse implementations handle this. + .flatMap(bytes -> (bytes == null || bytes.length == 0) + ? Mono.empty() + : Mono.just(bytes)); } @Override