checkNotModified needs to consider HEAD as well

Issue: SPR-11317
This commit is contained in:
Juergen Hoeller
2014-01-15 23:06:47 +01:00
parent a5f9b29292
commit 17cc63ef63
2 changed files with 63 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,6 +47,8 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
private static final String METHOD_GET = "GET";
private static final String METHOD_HEAD = "HEAD";
private HttpServletResponse response;
@@ -173,7 +175,7 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
long ifModifiedSince = getRequest().getDateHeader(HEADER_IF_MODIFIED_SINCE);
this.notModified = (ifModifiedSince >= (lastModifiedTimestamp / 1000 * 1000));
if (this.response != null) {
if (this.notModified && METHOD_GET.equals(getRequest().getMethod())) {
if (this.notModified && supportsNotModifiedStatus()) {
this.response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
}
else {
@@ -191,7 +193,7 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
String ifNoneMatch = getRequest().getHeader(HEADER_IF_NONE_MATCH);
this.notModified = eTag.equals(ifNoneMatch);
if (this.response != null) {
if (this.notModified && METHOD_GET.equals(getRequest().getMethod())) {
if (this.notModified && supportsNotModifiedStatus()) {
this.response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
}
else {
@@ -200,7 +202,11 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
}
}
return this.notModified;
}
private boolean supportsNotModifiedStatus() {
String method = getRequest().getMethod();
return (METHOD_GET.equals(method) || METHOD_HEAD.equals(method));
}
public boolean isNotModified() {