Skip to content

Commit

Permalink
Fix azure-core-http-jdk-httpclient Tests (#24511)
Browse files Browse the repository at this point in the history
Fix azure-core-http-jdk-httpclient Tests
  • Loading branch information
alzimmermsft authored Oct 4, 2021
1 parent 72b460d commit 15789cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ private Mono<java.net.http.HttpRequest> 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 "
Expand Down Expand Up @@ -135,7 +134,7 @@ private static BodyPublisher toBodyPublisher(Flux<ByteBuffer> bbPublisher, Strin
} else {
long contentLengthLong = Long.parseLong(contentLength);
if (contentLengthLong < 1) {
return fromPublisher(bbFlowPublisher);
return noBody();
} else {
return fromPublisher(bbFlowPublisher, contentLengthLong);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ public Flux<ByteBuffer> getBody() {

@Override
public Mono<byte[]> 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
Expand Down

0 comments on commit 15789cd

Please sign in to comment.