Refine Content-Range support for Resources
This commit restricts the support of `"Content-Range"` when returning `Resource` instances from Controllers - now only "HTTP 200 OK" responses will be considered, as Controllers might want to handle content range themselves. Issue: SPR-16921
This commit is contained in:
@@ -568,8 +568,24 @@ public class HttpEntityMethodProcessorMockTests {
|
||||
assertThat(servletResponse.getHeader(HttpHeaders.ACCEPT_RANGES), Matchers.isEmptyOrNullString());
|
||||
}
|
||||
|
||||
@Test //SPR-16921
|
||||
public void disableRangeSupportIfContentRangePresent() throws Exception {
|
||||
ResponseEntity<Resource> returnValue = ResponseEntity
|
||||
.status(HttpStatus.PARTIAL_CONTENT)
|
||||
.header(HttpHeaders.RANGE, "bytes=0-5")
|
||||
.body(new ByteArrayResource("Content".getBytes(StandardCharsets.UTF_8)));
|
||||
|
||||
given(resourceRegionMessageConverter.canWrite(any(), eq(null))).willReturn(true);
|
||||
given(resourceRegionMessageConverter.canWrite(any(), eq(APPLICATION_OCTET_STREAM))).willReturn(true);
|
||||
|
||||
processor.handleReturnValue(returnValue, returnTypeResponseEntityResource, mavContainer, webRequest);
|
||||
|
||||
then(resourceRegionMessageConverter).should(never()).write(anyCollection(), any(), any());
|
||||
assertEquals(206, servletResponse.getStatus());
|
||||
}
|
||||
|
||||
@Test //SPR-14767
|
||||
public void shouldHandleValidatorHeadersInPutResponses() throws Exception {
|
||||
public void shouldHandleValidatorHeadersInputResponses() throws Exception {
|
||||
servletRequest.setMethod("PUT");
|
||||
String etagValue = "\"some-etag\"";
|
||||
ResponseEntity<String> returnValue = ResponseEntity.ok().header(HttpHeaders.ETAG, etagValue).body("body");
|
||||
|
||||
Reference in New Issue
Block a user