From 15789cd01a26c2afdcffa23e7ed7f7f6cdbc28fb Mon Sep 17 00:00:00 2001 From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Date: Mon, 4 Oct 2021 10:46:11 -0700 Subject: [PATCH] Fix azure-core-http-jdk-httpclient Tests (#24511) Fix azure-core-http-jdk-httpclient Tests --- .../azure/core/http/jdk/httpclient/JdkAsyncHttpClient.java | 5 ++--- .../com/azure/core/http/jdk/httpclient/JdkHttpResponse.java | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) 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