Author: ivaynberg
Date: Tue Mar 2 01:07:40 2010
New Revision: 917829
URL: http://svn.apache.org/viewvc?rev=917829&view=rev
Log:
always output expires and last-mod headers for resources even if they were not
modified since
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/resource/AbstractResource.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WebExternalResourceTest.java
wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/resource/AbstractResource.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/resource/AbstractResource.java?rev=917829&r1=917828&r2=917829&view=diff
==============================================================================
---
wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/resource/AbstractResource.java
(original)
+++
wicket/trunk/wicket/src/main/java/org/apache/wicket/ng/resource/AbstractResource.java
Tue Mar 2 01:07:40 2010
@@ -337,6 +337,18 @@
WebRequest request = (WebRequest)attributes.getRequest();
WebResponse response = (WebResponse)attributes.getResponse();
+
+ // 1. Last Modified
+ Date lastModified = data.getLastModified();
+ if (lastModified != null)
+ {
+ response.setLastModifiedTime(lastModified.getTime());
+ }
+
+ // 2. Caching
+
+ configureCache(request, response, data, attributes);
+
if (!data.dataNeedsToBeWritten(attributes))
{
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
@@ -358,7 +370,7 @@
ContentDisposition disposition =
data.getContentDisposition();
String mimeType = data.getContentType();
String encoding = null;
- Date lastModified = data.getLastModified();
+
if (mimeType != null && mimeType.indexOf("text") != -1)
{
@@ -367,7 +379,7 @@
long contentLength = data.getContentLength();
- // 1. Content Disposition
+ // 3. Content Disposition
if (ContentDisposition.ATTACHMENT == disposition)
{
@@ -378,7 +390,7 @@
response.setInlineHeader(fileName);
}
- // 2. Mime Type (+ encoding)
+ // 4. Mime Type (+ encoding)
if (mimeType != null)
{
@@ -392,16 +404,6 @@
}
}
- // 3. Last Modified
-
- if (lastModified != null)
- {
-
response.setLastModifiedTime(lastModified.getTime());
- }
-
- // 4. Caching
-
- configureCache(request, response, data, attributes);
// 5. Content Length
Modified:
wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WebExternalResourceTest.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WebExternalResourceTest.java?rev=917829&r1=917828&r2=917829&view=diff
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WebExternalResourceTest.java
(original)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WebExternalResourceTest.java
Tue Mar 2 01:07:40 2010
@@ -45,11 +45,10 @@
Streams.copy(in, out);
in.close();
out.close();
- tester = new WicketTester(new DummyWebApplication(),
tempDir.getPath());
- tester.setupRequestAndResponse();
+ tester = new WicketTester(tempDir.getPath());
// We fake the browser URL, otherwise Wicket doesn't know the
requested URL and cannot guess
// the Content-Type
- tester.getServletRequest().setPath("/index.html");
+ tester.getRequest().setPath("/index.html");
}
/**
Modified:
wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java?rev=917829&r1=917828&r2=917829&view=diff
==============================================================================
---
wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java
(original)
+++
wicket/trunk/wicket/src/test/java/org/apache/wicket/protocol/http/WicketFilterTest.java
Tue Mar 2 01:07:40 2010
@@ -92,12 +92,19 @@
{
throw new
UnsupportedOperationException("Not implemented");
}
+
+ @Override
+ protected ResourceResponse
newResourceResponse(Attributes attributes)
+ {
+ ResourceResponse response =
super.newResourceResponse(attributes);
+ response.setCacheable(true);
+ return response;
+ }
};
- // resource.setCacheable(true);
application.getSharedResources().add("foo.gif",
resource);
MockHttpServletRequest request = new
MockHttpServletRequest(application, null, null);
- request.setURL(request.getContextPath() + "/app/" +
"resources/" +
- Application.class.getName() + "/foo.gif");
+ request.setURL(request.getContextPath() +
request.getServletPath() +
+ "/wicket/resource/" +
Application.class.getName() + "/foo.gif");
setIfModifiedSinceToNextWeek(request);
MockHttpServletResponse response = new
MockHttpServletResponse(request);
filter.doFilter(request, response, new FilterChain()
@@ -107,7 +114,7 @@
{
}
});
- assertEquals(HttpServletResponse.SC_NOT_MODIFIED,
response.getStatus());
+
assertEquals((Integer)HttpServletResponse.SC_NOT_MODIFIED,
response.getStatus());
String responseExpiresHeader =
response.getHeader("Expires");
assertNotNull("Expires header must be set on not
modified response",
responseExpiresHeader);
@@ -169,7 +176,7 @@
{
initParameters.put(WicketFilter.APP_FACT_PARAM,
FilterTestingApplicationFactory.class.getName());
- initParameters.put(WicketFilter.FILTER_MAPPING_PARAM,
"/app/*");
+ initParameters.put(WicketFilter.FILTER_MAPPING_PARAM,
"/servlet/*");
initParameters.put(ContextParamWebApplicationFactory.APP_CLASS_PARAM,
MockApplication.class.getName());
}