Skip to content

Commit ec62153

Browse files
authored
Merge pull request #2731 from nikeee/http-range
Return correct error body on invalid ranges
2 parents 257acae + f59288c commit ec62153

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

server/src/main/java/com/adobe/testing/s3mock/ObjectController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ private ResponseEntity<StreamingResponseBody> getObjectWithRange(
973973
var contentLength = endInclusive - startInclusive + 1;
974974

975975
if (contentLength < 0 || fileSize <= startInclusive) {
976-
return ResponseEntity.status(REQUESTED_RANGE_NOT_SATISFIABLE).build();
976+
throw S3Exception.INVALID_RANGE;
977977
}
978978

979979
return ResponseEntity

server/src/main/java/com/adobe/testing/s3mock/S3Exception.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.springframework.http.HttpStatus.BAD_REQUEST;
2020
import static org.springframework.http.HttpStatus.CONFLICT;
2121
import static org.springframework.http.HttpStatus.NOT_FOUND;
22+
import static org.springframework.http.HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE;
2223

2324
import com.adobe.testing.s3mock.dto.ErrorResponse;
2425
import org.springframework.http.HttpStatus;
@@ -32,6 +33,8 @@
3233
public class S3Exception extends RuntimeException {
3334
private static final String INVALID_REQUEST_CODE = "InvalidRequest";
3435
private static final String BAD_REQUEST_CODE = "BadRequest";
36+
private static final String REQUESTED_RANGE_NOT_SATISFIABLE_CODE = "InvalidRange";
37+
3538
public static final S3Exception INVALID_PART_NUMBER =
3639
new S3Exception(BAD_REQUEST.value(), "InvalidArgument",
3740
"Part number must be an integer between 1 and 10000, inclusive");
@@ -119,6 +122,10 @@ public static S3Exception completeRequestMissingChecksum(String algorithm, Integ
119122
+ "changing the object's metadata, storage class, website redirect location or "
120123
+ "encryption attributes.");
121124

125+
public static final S3Exception INVALID_RANGE =
126+
new S3Exception(REQUESTED_RANGE_NOT_SATISFIABLE.value(), REQUESTED_RANGE_NOT_SATISFIABLE_CODE,
127+
"Invalid http range.");
128+
122129
public static final S3Exception BAD_REQUEST_MD5 =
123130
new S3Exception(BAD_REQUEST.value(), BAD_REQUEST_CODE,
124131
"Content-MD5 does not match object md5");

server/src/test/kotlin/com/adobe/testing/s3mock/ObjectControllerTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,7 @@ internal class ObjectControllerTest : BaseControllerTest() {
918918
.header("Range", "bytes=9999999-10000000")
919919
)
920920
.andExpect(status().isRequestedRangeNotSatisfiable)
921+
.andExpect(content().string(MAPPER.writeValueAsString(from(S3Exception.INVALID_RANGE))))
921922
}
922923

923924
@Test

0 commit comments

Comments
 (0)