From 924d94d58c2b34fce9224606b660c69212c61036 Mon Sep 17 00:00:00 2001 From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Date: Fri, 1 Oct 2021 18:25:59 -0700 Subject: [PATCH 1/2] Fixed most JDK HttpClient tests --- .../azure/core/http/jdk/httpclient/JdkAsyncHttpClient.java | 5 ++--- .../com/azure/core/http/jdk/httpclient/JdkHttpResponse.java | 2 +- 2 files changed, 3 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..49de1f564ef8a 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,7 @@ public Flux getBody() { @Override public Mono getBodyAsByteArray() { - return FluxUtil.collectBytesFromNetworkResponse(getBody(), getHeaders()); + return FluxUtil.collectBytesInByteBufferStream(getBody()); } @Override From 3c288705bc9cf796ca9111b7c2e9e8068dec40b3 Mon Sep 17 00:00:00 2001 From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Date: Mon, 4 Oct 2021 09:32:55 -0700 Subject: [PATCH 2/2] Fix azure-core-http-jdk-httpclient Tests --- .../com/azure/core/http/jdk/httpclient/JdkHttpResponse.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 49de1f564ef8a..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.collectBytesInByteBufferStream(getBody()); + 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