Issue: WebKit based browsers don't get resources correctly in
Development mode
I'm pretty sure there is some history around this so I'm mailing it to
the list before filing an issue. I *do* know that the following
happens.
I have a simple JSF View with a CSS that lives in a resource library.
When I browse the view in Firefox, I see the CSS is applied. When I
browse it in a WebKit based browser (Chrome and Safari), it is not.
Further inspection reveals that WebKit gets sent the 304 always in
response to the request to the CSS stylesheet, whereas Firefox does not.
I observed some strange behavior in trying to clear out my browser's
cache in Firefox and Safari. Sometimes, Firefox would not send an
If-Modified-Since header at all, other times it would.
I also know that I no longer observe this problem after applying the
patch here.
Ryan or someone else, is this a real bug? Can I file it and check in
this fix?
SECTION: Modified Files
----------------------------
M jsf-ri/src/com/sun/faces/application/resource/ResourceImpl.java
SECTION: Diffs
----------------------------
Index: jsf-ri/src/com/sun/faces/application/resource/ResourceImpl.java
===================================================================
--- jsf-ri/src/com/sun/faces/application/resource/ResourceImpl.java
(revision 8233)
+++ jsf-ri/src/com/sun/faces/application/resource/ResourceImpl.java
(working copy)
@@ -43,6 +43,7 @@
import java.io.ObjectInput;
import java.net.URL;
import java.net.URLConnection;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
@@ -50,6 +51,8 @@
import java.util.Map;
import java.util.TimeZone;
import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.faces.application.Resource;
import javax.faces.context.FacesContext;
@@ -315,12 +318,38 @@
*/
public boolean userAgentNeedsUpdate(FacesContext context) {
+ //
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
+ // 14.25 If-Modified-Since
+
+ // if the requested variant has not been modified since the time
+ // specified in this field, an entity will not be returned from the
+ // server; instead, a 304 (not modified) response will be returned
+ // without any message-body.
+
+ // A date which is later than the server's current time is
+ // invalid.
+
Map<String,String> requestHeaders =
context.getExternalContext().getRequestHeaderMap();
- return ((!requestHeaders.containsKey("If-Modified-Since"))
- || (resourceInfo.getHelper()
- .getLastModified(resourceInfo, context) >
initialTime));
+ boolean result = true;
+ if (requestHeaders.containsKey("If-Modified-Since")) {
+ SimpleDateFormat format =
+ new SimpleDateFormat(RFC1123_DATE_PATTERN, Locale.US);
+ Date ifModifiedSinceDate = null;
+ try {
+ ifModifiedSinceDate = format.parse(requestHeaders.
+ get("If-Modified-Since"));
+ long lastModified = resourceInfo.getHelper()
+ .getLastModified(resourceInfo, context);
+ result = lastModified > ifModifiedSinceDate.getTime();
+ } catch (ParseException ex) {
+
+ }
+
+ }
+ return result;
+
}