Fix server errors for invalid If-None-Match request headers

HttpEntityMethodProcessor should not throw IllegalArgumentExceptions for
invalid If-None-Match headers.

For those cases, this commit makes sure that both
`HttpEntityMethodProcessor` and `ServletWebRequest` have a consistent
behavior and stop processing the request as conditional and leave the
handler handle it.

Issue: SPR-14559
This commit is contained in:
Brian Clozel
2016-08-26 15:33:02 +02:00
parent 5998a297ce
commit d8fc13f6fc
3 changed files with 44 additions and 16 deletions

View File

@@ -379,6 +379,21 @@ public class HttpEntityMethodProcessorMockTests {
assertEquals(etagValue, servletResponse.getHeader(HttpHeaders.ETAG));
}
@Test // SPR-14559
public void handleReturnValueEtagInvalidIfNoneMatch() throws Exception {
String etagValue = "\"deadb33f8badf00d\"";
servletRequest.addHeader(HttpHeaders.IF_NONE_MATCH, "unquoted");
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.set(HttpHeaders.ETAG, etagValue);
ResponseEntity<String> returnValue = new ResponseEntity<>("body", responseHeaders, HttpStatus.OK);
initStringMessageConversion(MediaType.TEXT_PLAIN);
processor.handleReturnValue(returnValue, returnTypeResponseEntity, mavContainer, webRequest);
assertTrue(mavContainer.isRequestHandled());
assertEquals(HttpStatus.OK.value(), servletResponse.getStatus());
}
@Test
public void handleReturnValueETagAndLastModified() throws Exception {
long currentTime = new Date().getTime();