Browse Source

Guard against invalid response status

ServletWebRequest now guard against invalid HTTP response status when
processing conditional requests.

Issue: SPR-13516
pull/880/head
Brian Clozel 9 years ago
parent
commit
39726740e5
  1. 10
      spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java
  2. 12
      spring-web/src/test/java/org/springframework/web/context/request/ServletWebRequestHttpMethodsTests.java

10
spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java

@ -244,11 +244,15 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ @@ -244,11 +244,15 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
private boolean isCompatibleWithConditionalRequests(HttpServletResponse response) {
if (response == null || !servlet3Present) {
// Can't check response.getStatus() - let's assume we're good
try {
if (response == null || !servlet3Present) {
// Can't check response.getStatus() - let's assume we're good
return true;
}
return HttpStatus.valueOf(response.getStatus()).is2xxSuccessful();
} catch (IllegalArgumentException e) {
return true;
}
return HttpStatus.valueOf(response.getStatus()).is2xxSuccessful();
}
private boolean isHeaderAbsent(HttpServletResponse response, String header) {

12
spring-web/src/test/java/org/springframework/web/context/request/ServletWebRequestHttpMethodsTests.java

@ -87,6 +87,18 @@ public class ServletWebRequestHttpMethodsTests { @@ -87,6 +87,18 @@ public class ServletWebRequestHttpMethodsTests {
assertNull(servletResponse.getHeader("Last-Modified"));
}
// SPR-13516
@Test
public void checkNotModifiedInvalidStatus() {
long epochTime = currentDate.getTime();
servletRequest.addHeader("If-Modified-Since", epochTime);
servletResponse.setStatus(0);
assertTrue(request.checkNotModified(epochTime));
assertEquals(304, servletResponse.getStatus());
assertEquals(dateFormat.format(epochTime), servletResponse.getHeader("Last-Modified"));
}
@Test
public void checkNotModifiedHeaderAlreadySet() {
long epochTime = currentDate.getTime();

Loading…
Cancel
Save