Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix azure-core-http-jdk-httpclient Tests #24511

Merged
merged 3 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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