HDDS-894. Content-length should be set for ozone s3 ranged download. Contributed by Elek Marton.

This commit is contained in:
Bharat Viswanadham 2018-12-03 15:17:44 -08:00
parent fb9deed41d
commit de4255509a
2 changed files with 10 additions and 3 deletions

View File

@ -56,6 +56,7 @@
import org.apache.hadoop.util.Time;
import com.google.common.annotations.VisibleForTesting;
import static javax.ws.rs.core.HttpHeaders.CONTENT_LENGTH;
import static javax.ws.rs.core.HttpHeaders.LAST_MODIFIED;
import org.apache.commons.io.IOUtils;
import static org.apache.hadoop.ozone.s3.util.S3Consts.ACCEPT_RANGE_HEADER;
@ -204,10 +205,12 @@ public Response get(
IOUtils.copy(key, dest);
}
};
responseBuilder = Response.ok(output);
responseBuilder = Response
.ok(output)
.header(CONTENT_LENGTH, keyDetails.getDataSize());
} else {
LOG.info("range Header provided value is {}", rangeHeader);
LOG.debug("range Header provided value is {}", rangeHeader);
OzoneInputStream key = bucket.readKey(keyPath);
long startOffset = rangeHeader.getStartOffset();
@ -229,7 +232,9 @@ public Response get(
copyLength);
}
};
responseBuilder = Response.ok(output);
responseBuilder = Response
.ok(output)
.header(CONTENT_LENGTH, copyLength);
String contentRangeVal = RANGE_HEADER_SUPPORTED_UNIT + " " +
rangeHeader.getStartOffset() + "-" + rangeHeader.getEndOffset() +

View File

@ -80,6 +80,8 @@ public void get() throws IOException, OS3Exception {
IOUtils.toString(ozoneInputStream, Charset.forName("UTF-8"));
Assert.assertEquals(CONTENT, keyContent);
Assert.assertEquals("" + keyContent.length(),
response.getHeaderString("Content-Length"));
DateTimeFormatter.RFC_1123_DATE_TIME
.parse(response.getHeaderString("Last-Modified"));