Fix null content-length header on HEAD requests

https://issues.apache.org/jira/projects/JCLOUDS/issues/JCLOUDS-1505
This commit is contained in:
Xavier BOURGOUIN 2019-10-10 17:40:29 +02:00 committed by Andrew Gaul
parent 6ef0937c67
commit c445547ea8
1 changed files with 4 additions and 2 deletions

View File

@ -88,7 +88,7 @@ public class ApacheHCHttpCommandExecutorService extends BaseHttpCommandExecutorS
org.apache.http.HttpResponse apacheResponse = executeRequest(nativeRequest);
Payload payload = null;
if (apacheResponse.getEntity() != null)
if (apacheResponse.getEntity() != null) {
try {
payload = Payloads.newInputStreamPayload(apacheResponse.getEntity().getContent());
if (apacheResponse.getEntity().getContentLength() >= 0)
@ -99,17 +99,19 @@ public class ApacheHCHttpCommandExecutorService extends BaseHttpCommandExecutorS
logger.warn(e, "couldn't receive payload for request: %s", nativeRequest.getRequestLine());
throw e;
}
}
Multimap<String, String> headers = LinkedHashMultimap.create();
for (Header header : apacheResponse.getAllHeaders()) {
headers.put(header.getName(), header.getValue());
}
if (payload != null) {
contentMetadataCodec.fromHeaders(payload.getContentMetadata(), headers);
headers = filterOutContentHeaders(headers);
}
return HttpResponse.builder().statusCode(apacheResponse.getStatusLine().getStatusCode())
.message(apacheResponse.getStatusLine().getReasonPhrase())
.payload(payload)
.headers(filterOutContentHeaders(headers)).build();
.headers(headers).build();
}
private org.apache.http.HttpResponse executeRequest(HttpUriRequest nativeRequest) throws IOException,