|
|
@ -19,7 +19,6 @@ package org.springframework.web.context.request; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Locale; |
|
|
|
import java.util.Locale; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletRequest; |
|
|
|
import javax.servlet.ServletRequest; |
|
|
|
import javax.servlet.ServletResponse; |
|
|
|
import javax.servlet.ServletResponse; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
@ -118,75 +117,90 @@ public class ServletWebRequestTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void checkNotModifiedTimeStampForGET() { |
|
|
|
public void checkNotModifiedTimestampForGET() { |
|
|
|
long currentTime = new Date().getTime(); |
|
|
|
long currentTime = new Date().getTime(); |
|
|
|
servletRequest.setMethod("GET"); |
|
|
|
servletRequest.setMethod("GET"); |
|
|
|
servletRequest.addHeader("If-Modified-Since", currentTime); |
|
|
|
servletRequest.addHeader("If-Modified-Since", currentTime); |
|
|
|
|
|
|
|
|
|
|
|
request.checkNotModified(currentTime); |
|
|
|
assertTrue(request.checkNotModified(currentTime)); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(304, servletResponse.getStatus()); |
|
|
|
assertEquals(304, servletResponse.getStatus()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void checkModifiedTimeStampForGET() { |
|
|
|
public void checkModifiedTimestampForGET() { |
|
|
|
long currentTime = new Date().getTime(); |
|
|
|
long currentTime = new Date().getTime(); |
|
|
|
long oneMinuteAgo = currentTime - (1000 * 60); |
|
|
|
long oneMinuteAgo = currentTime - (1000 * 60); |
|
|
|
servletRequest.setMethod("GET"); |
|
|
|
servletRequest.setMethod("GET"); |
|
|
|
servletRequest.addHeader("If-Modified-Since", oneMinuteAgo); |
|
|
|
servletRequest.addHeader("If-Modified-Since", oneMinuteAgo); |
|
|
|
|
|
|
|
|
|
|
|
request.checkNotModified(currentTime); |
|
|
|
assertFalse(request.checkNotModified(currentTime)); |
|
|
|
|
|
|
|
assertEquals(200, servletResponse.getStatus()); |
|
|
|
|
|
|
|
assertEquals("" + currentTime, servletResponse.getHeader("Last-Modified")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void checkNotModifiedTimestampForHEAD() { |
|
|
|
|
|
|
|
long currentTime = new Date().getTime(); |
|
|
|
|
|
|
|
servletRequest.setMethod("HEAD"); |
|
|
|
|
|
|
|
servletRequest.addHeader("If-Modified-Since", currentTime); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertTrue(request.checkNotModified(currentTime)); |
|
|
|
|
|
|
|
assertEquals(304, servletResponse.getStatus()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void checkModifiedTimestampForHEAD() { |
|
|
|
|
|
|
|
long currentTime = new Date().getTime(); |
|
|
|
|
|
|
|
long oneMinuteAgo = currentTime - (1000 * 60); |
|
|
|
|
|
|
|
servletRequest.setMethod("HEAD"); |
|
|
|
|
|
|
|
servletRequest.addHeader("If-Modified-Since", oneMinuteAgo); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertFalse(request.checkNotModified(currentTime)); |
|
|
|
assertEquals(200, servletResponse.getStatus()); |
|
|
|
assertEquals(200, servletResponse.getStatus()); |
|
|
|
assertEquals(""+currentTime, servletResponse.getHeader("Last-Modified")); |
|
|
|
assertEquals(""+currentTime, servletResponse.getHeader("Last-Modified")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void checkNotModifiedETagForGET() { |
|
|
|
public void checkNotModifiedTimestampWithLengthPart() { |
|
|
|
String eTag = "\"Foo\""; |
|
|
|
long currentTime = Date.parse("Wed, 09 Apr 2014 09:57:42 GMT"); |
|
|
|
servletRequest.setMethod("GET"); |
|
|
|
servletRequest.setMethod("GET"); |
|
|
|
servletRequest.addHeader("If-None-Match", eTag ); |
|
|
|
servletRequest.addHeader("If-Modified-Since", "Wed, 09 Apr 2014 09:57:42 GMT; length=13774"); |
|
|
|
|
|
|
|
|
|
|
|
request.checkNotModified(eTag); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertTrue(request.checkNotModified(currentTime)); |
|
|
|
assertEquals(304, servletResponse.getStatus()); |
|
|
|
assertEquals(304, servletResponse.getStatus()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void checkModifiedETagForGET() { |
|
|
|
public void checkModifiedTimestampWithLengthPart() { |
|
|
|
String currentETag = "\"Foo\""; |
|
|
|
long currentTime = Date.parse("Wed, 09 Apr 2014 09:57:42 GMT"); |
|
|
|
String oldEtag = "Bar"; |
|
|
|
|
|
|
|
servletRequest.setMethod("GET"); |
|
|
|
servletRequest.setMethod("GET"); |
|
|
|
servletRequest.addHeader("If-None-Match", oldEtag); |
|
|
|
servletRequest.addHeader("If-Modified-Since", "Wed, 08 Apr 2014 09:57:42 GMT; length=13774"); |
|
|
|
|
|
|
|
|
|
|
|
request.checkNotModified(currentETag); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertFalse(request.checkNotModified(currentTime)); |
|
|
|
assertEquals(200, servletResponse.getStatus()); |
|
|
|
assertEquals(200, servletResponse.getStatus()); |
|
|
|
assertEquals(currentETag, servletResponse.getHeader("ETag")); |
|
|
|
assertEquals("" + currentTime, servletResponse.getHeader("Last-Modified")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void checkNotModifiedTimeStampForHEAD() { |
|
|
|
public void checkNotModifiedETagForGET() { |
|
|
|
long currentTime = new Date().getTime(); |
|
|
|
String eTag = "\"Foo\""; |
|
|
|
servletRequest.setMethod("HEAD"); |
|
|
|
servletRequest.setMethod("GET"); |
|
|
|
servletRequest.addHeader("If-Modified-Since", currentTime); |
|
|
|
servletRequest.addHeader("If-None-Match", eTag ); |
|
|
|
|
|
|
|
|
|
|
|
request.checkNotModified(currentTime); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertTrue(request.checkNotModified(eTag)); |
|
|
|
assertEquals(304, servletResponse.getStatus()); |
|
|
|
assertEquals(304, servletResponse.getStatus()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void checkModifiedTimeStampForHEAD() { |
|
|
|
public void checkModifiedETagForGET() { |
|
|
|
long currentTime = new Date().getTime(); |
|
|
|
String currentETag = "\"Foo\""; |
|
|
|
long oneMinuteAgo = currentTime - (1000 * 60); |
|
|
|
String oldEtag = "Bar"; |
|
|
|
servletRequest.setMethod("HEAD"); |
|
|
|
servletRequest.setMethod("GET"); |
|
|
|
servletRequest.addHeader("If-Modified-Since", oneMinuteAgo); |
|
|
|
servletRequest.addHeader("If-None-Match", oldEtag); |
|
|
|
|
|
|
|
|
|
|
|
request.checkNotModified(currentTime); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertFalse(request.checkNotModified(currentETag)); |
|
|
|
assertEquals(200, servletResponse.getStatus()); |
|
|
|
assertEquals(200, servletResponse.getStatus()); |
|
|
|
assertEquals(""+currentTime, servletResponse.getHeader("Last-Modified")); |
|
|
|
assertEquals(currentETag, servletResponse.getHeader("ETag")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -195,8 +209,7 @@ public class ServletWebRequestTests { |
|
|
|
servletRequest.setMethod("HEAD"); |
|
|
|
servletRequest.setMethod("HEAD"); |
|
|
|
servletRequest.addHeader("If-None-Match", eTag ); |
|
|
|
servletRequest.addHeader("If-None-Match", eTag ); |
|
|
|
|
|
|
|
|
|
|
|
request.checkNotModified(eTag); |
|
|
|
assertTrue(request.checkNotModified(eTag)); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(304, servletResponse.getStatus()); |
|
|
|
assertEquals(304, servletResponse.getStatus()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -207,8 +220,7 @@ public class ServletWebRequestTests { |
|
|
|
servletRequest.setMethod("HEAD"); |
|
|
|
servletRequest.setMethod("HEAD"); |
|
|
|
servletRequest.addHeader("If-None-Match", oldEtag); |
|
|
|
servletRequest.addHeader("If-None-Match", oldEtag); |
|
|
|
|
|
|
|
|
|
|
|
request.checkNotModified(currentETag); |
|
|
|
assertFalse(request.checkNotModified(currentETag)); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals(200, servletResponse.getStatus()); |
|
|
|
assertEquals(200, servletResponse.getStatus()); |
|
|
|
assertEquals(currentETag, servletResponse.getHeader("ETag")); |
|
|
|
assertEquals(currentETag, servletResponse.getHeader("ETag")); |
|
|
|
} |
|
|
|
} |
|
|
|