Skip to content

Commit

Permalink
Azure core fix for storage playback tests. (#4035)
Browse files Browse the repository at this point in the history
* Make changes to not override the header content length
  • Loading branch information
sima-zhu committed Jun 21, 2019
1 parent 951d4ea commit ceae510
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private Mono<HttpResponse> playbackHttpResponse(final HttpRequest request) {
HttpHeaders headers = new HttpHeaders();

for (Map.Entry<String, String> pair : networkCallRecord.response().entrySet()) {
if (!pair.getKey().equals("StatusCode") && !pair.getKey().equals("Body") && !pair.getKey().equals("Content-Length")) {
if (!pair.getKey().equals("StatusCode") && !pair.getKey().equals("Body")) {
String rawHeader = pair.getValue();
for (Map.Entry<String, String> rule : textReplacementRules.entrySet()) {
if (rule.getValue() != null) {
Expand All @@ -122,7 +122,9 @@ private Mono<HttpResponse> playbackHttpResponse(final HttpRequest request) {
}

bytes = rawBody.getBytes(StandardCharsets.UTF_8);
headers.put("Content-Length", String.valueOf(bytes.length));
if (bytes.length > 0) {
headers.put("Content-Length", String.valueOf(bytes.length));
}
}

HttpResponse response = new MockHttpResponse(request, recordStatusCode, headers, bytes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.zip.GZIPInputStream;
Expand Down Expand Up @@ -98,7 +97,7 @@ private Mono<Map<String, String>> extractResponseData(final HttpResponse respons
headerValueToStore = "0";
addedRetryAfter = true;
}
responseData.put(header.name().toLowerCase(Locale.US), headerValueToStore);
responseData.put(header.name(), headerValueToStore);
}

if (!addedRetryAfter) {
Expand All @@ -109,7 +108,7 @@ private Mono<Map<String, String>> extractResponseData(final HttpResponse respons
if (contentType == null) {
return Mono.just(responseData);
} else if (contentType.contains("json") || response.headerValue("content-encoding") == null) {
return response.bodyAsString().map(content -> {
return response.bodyAsString().switchIfEmpty(Mono.just("")).map(content -> {
responseData.put("Body", content);
return responseData;
});
Expand Down

0 comments on commit ceae510

Please sign in to comment.