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:
Brian Clozel
2018-07-10 12:11:23 +02:00
parent d5df097e0e
commit 818e4b0776
2 changed files with 21 additions and 3 deletions

View File

@@ -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");