Skip to content

Commit

Permalink
GetObjectRequest should support final bytes as a Range header value
Browse files Browse the repository at this point in the history
Fixes aws#1551
  • Loading branch information
omalley committed Dec 20, 2019
1 parent 9b656cf commit b5a8532
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Expand Up @@ -1461,7 +1461,11 @@ public S3Object getObject(GetObjectRequest getObjectRequest)
// Range
long[] range = getObjectRequest.getRange();
if (range != null) {
request.addHeader(Headers.RANGE, "bytes=" + Long.toString(range[0]) + "-" + Long.toString(range[1]));
if (range[0] < 0) {
request.addHeader(Headers.RANGE, "bytes=" + Long.toString(range[0]));
} else {
request.addHeader(Headers.RANGE, "bytes=" + Long.toString(range[0]) + "-" + Long.toString(range[1]));
}
}

populateRequesterPaysHeader(request, getObjectRequest.isRequesterPays());
Expand Down
Expand Up @@ -474,7 +474,10 @@ public void setRange(long start, long end) {
* <p>
* The first byte in an object has
* position 0; as an example, the object is of 10 bytes in length, the last
* 4 bytes can be downloaded by specifying the start range as 6.
* 4 bytes can be downloaded by specifying the start range as 6. Positions
* may also be specified as a negative number counting from the end of the
* object. Therefore, start = -4 will get the last four bytes of the
* object regardless of its length.
* </p>
* <p>
* If no byte range is specified, this request downloads the entire
Expand Down Expand Up @@ -534,7 +537,10 @@ public GetObjectRequest withRange(long start, long end) {
* <p>
* The first byte in an object has
* position 0; as an example, the object is of 10 bytes in length, the last
* 4 bytes can be downloaded by specifying the start range as 6.
* 4 bytes can be downloaded by specifying the start range as 6. Positions
* may also be specified as a negative number counting from the end of the
* object. Therefore, start = -4 will get the last four bytes of the
* object regardless of its length.
* </p>
* <p>
* If no byte range is specified, this request downloads the entire
Expand Down

0 comments on commit b5a8532

Please sign in to comment.