You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by ts...@apache.org on 2016/10/01 13:51:32 UTC

wicket git commit: WICKET-6194 - Fix if-modified-since parsing / add some more doc

Repository: wicket
Updated Branches:
  refs/heads/master 4b0137e67 -> 1d30a3aca


WICKET-6194 - Fix if-modified-since parsing / add some more doc

Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/1d30a3ac
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/1d30a3ac
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/1d30a3ac

Branch: refs/heads/master
Commit: 1d30a3acab77862c111cac24d82a4a74f857abfd
Parents: 4b0137e
Author: Tobias Soloschenko <ts...@apache.org>
Authored: Sat Oct 1 15:49:49 2016 +0200
Committer: Tobias Soloschenko <ts...@apache.org>
Committed: Sat Oct 1 15:49:49 2016 +0200

----------------------------------------------------------------------
 .../http2/markup/head/PushHeaderItem.java       | 94 +++++++++++++++-----
 .../src/docs/guide/http2push/http2push_1.gdoc   | 12 ++-
 2 files changed, 78 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/1d30a3ac/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushHeaderItem.java
----------------------------------------------------------------------
diff --git a/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushHeaderItem.java b/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushHeaderItem.java
index 8f6eb8b..97c6c95 100644
--- a/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushHeaderItem.java
+++ b/wicket-experimental/wicket-http2/wicket-http2-core/src/main/java/org/apache/wicket/http2/markup/head/PushHeaderItem.java
@@ -66,10 +66,22 @@ public class PushHeaderItem extends HeaderItem
 	private static final long serialVersionUID = 1L;
 
 	/**
-	 * The header date format for if-modified-since / last-modified
+	 * The header date formats for if-modified-since / last-modified
 	 */
-	private static final DateTimeFormatter headerDateFormat = DateTimeFormatter
-		.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz");
+	private static final DateTimeFormatter headerDateFormat_RFC1123 = DateTimeFormatter
+		.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz")
+		.withLocale(java.util.Locale.ENGLISH)
+		.withZone(ZoneOffset.UTC); // Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
+
+	private static final DateTimeFormatter headerDateFormat_RFC1036 = DateTimeFormatter
+		.ofPattern("EEEE, dd-MMM-yy HH:mm:ss zzz")
+		.withLocale(java.util.Locale.ENGLISH)
+		.withZone(ZoneOffset.UTC); // Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obs. by RFC 1036
+
+	private static final DateTimeFormatter headerDateFormat_ASCTIME = DateTimeFormatter
+		.ofPattern("EEE MMM d HH:mm:ss yyyy")
+		.withLocale(java.util.Locale.ENGLISH)
+		.withZone(ZoneOffset.UTC); // Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
 
 	/**
 	 * The http2 protocol string
@@ -213,39 +225,73 @@ public class PushHeaderItem extends HeaderItem
 		// Check if the protocol is http/2 or http/2.0 to only push the resources in this case
 		if (isHttp2(request))
 		{
-			try
+
+			Time pageModificationTime = getPageModificationTime();
+			String ifModifiedSinceHeader = pageWebRequest.getHeader("If-Modified-Since");
+
+			// Check if the if-modified-since header is set - if not push all resources
+			if (ifModifiedSinceHeader != null)
 			{
-				Time pageModificationTime = getPageModificationTime();
-				String ifModifiedSinceHeader = pageWebRequest.getHeader("If-Modified-Since");
 
-				// Check if the if-modified-since header is set - if not push all resources
-				if (ifModifiedSinceHeader != null)
+				// Try to parse RFC1123
+				Time ifModifiedSinceFromRequestTime = parseIfModifiedSinceHeader(
+					ifModifiedSinceHeader, headerDateFormat_RFC1123);
+
+				// Try to parse ASCTIME
+				if (ifModifiedSinceFromRequestTime == null)
 				{
-					// Get the time of the if-modified-since header
-					Time ifModifiedSinceFromRequestTime = Time.valueOf(Date.from(LocalDateTime
-						.parse(ifModifiedSinceHeader, headerDateFormat).toInstant(ZoneOffset.UTC)));
-
-					// If the client modification time is before the page modification time -
-					// don't push
-					if (ifModifiedSinceFromRequestTime.before(pageModificationTime))
-					{
-						// Push only if the "if-modified-since" time is before the page modification
-						push(request);
-					}
+					ifModifiedSinceFromRequestTime = parseIfModifiedSinceHeader(
+						ifModifiedSinceHeader, headerDateFormat_ASCTIME);
 				}
-				else
+
+				// Try to parse RFC1036 - because it is obsolete due to RFC 1036 check this last.
+				if (ifModifiedSinceFromRequestTime == null)
 				{
-					// Push the resources if the "if-modified-since" is not available
+					ifModifiedSinceFromRequestTime = parseIfModifiedSinceHeader(
+						ifModifiedSinceHeader, headerDateFormat_RFC1036);
+				}
+
+				// if the modified since header is before the page modification time or if it can't
+				// be parsed push it.
+				else if (ifModifiedSinceFromRequestTime == null ||
+					ifModifiedSinceFromRequestTime.before(pageModificationTime))
+				{
+					// Some browsers like IE 9-11 or Chrome 39 that does not send right headers
+					// receive the resource via push all the time
 					push(request);
 				}
 			}
-			catch (DateTimeParseException e)
+			else
 			{
-				// If the "if-modified-since" time can't be parsed - the push handling is going to
-				// be processed
+				// Push the resources if the "if-modified-since" is not available
 				push(request);
 			}
+
+		}
+	}
+
+	/**
+	 * Parses the given if modified since header with the date time formatter
+	 * 
+	 * @param ifModifiedSinceHeader
+	 *            the if modified since header string
+	 * @param dateTimeFormatter
+	 *            the formatter to parse the header string with
+	 * @return the time or null
+	 */
+	private Time parseIfModifiedSinceHeader(String ifModifiedSinceHeader,
+		DateTimeFormatter dateTimeFormatter)
+	{
+		try
+		{
+			return Time.valueOf(Date.from(LocalDateTime
+				.parse(ifModifiedSinceHeader, dateTimeFormatter).toInstant(ZoneOffset.UTC)));
+		}
+		catch (DateTimeParseException e)
+		{
+			// NOOP
 		}
+		return null;
 	}
 
 	/**

http://git-wip-us.apache.org/repos/asf/wicket/blob/1d30a3ac/wicket-user-guide/src/docs/guide/http2push/http2push_1.gdoc
----------------------------------------------------------------------
diff --git a/wicket-user-guide/src/docs/guide/http2push/http2push_1.gdoc b/wicket-user-guide/src/docs/guide/http2push/http2push_1.gdoc
index 03af6d4..8c954ed 100644
--- a/wicket-user-guide/src/docs/guide/http2push/http2push_1.gdoc
+++ b/wicket-user-guide/src/docs/guide/http2push/http2push_1.gdoc
@@ -8,7 +8,7 @@ Current supported servers are:
 
 For the setup you need to follow those steps:
 
-1. Setup your server to use HTTP/2 and follow the instructions provided by the vendor specific documentation
+1. Setup your server to use HTTP/2 and follow the instructions provided by the vendor specific documentation. (Because of HTTP/2 a HTTPS setup is also required)
 
 2. Add the respective dependency for your web server to provide the push functionality.
 {code}
@@ -28,9 +28,9 @@ public class HTTP2Page extends WebPage
 {
 	private static final long serialVersionUID = 1L;
 
-	private transient Response webPageResponse;
+	private Response webPageResponse;
 
-	private transient Request webPageRequest;
+	private Request webPageRequest;
 
 	public HTTP2Page()
 	{
@@ -65,4 +65,8 @@ The PushHeaderItem behaves like explained in the following steps:
 * When a browser requests the page a second time and the markup of the page has changed everything is going to be pushed again (200)
 * When a browser requests the page a second time and resource references has been changed but not the page markup, all changed resource references are shipped via separate requests
 
-Note: Chrome does not set cache headers if the https connection is not secure (self signed) / valid - so ensure that a valid https connection is available with your server.
\ No newline at end of file
+Note: Chrome does not set cache headers if the https connection is not secure (self signed) / valid - so ensure that a valid https connection is available with your server. "Browser not caching files if HTTPS is used even if it's allowed by webserver via response headers":https://bugs.chromium.org/p/chromium/issues/detail?id=110649
+
+If you want to change the cache behavior to not only look at the markup of the page and based on this proceed the push, override the method *protected Time getPageModificationTime()* of the PushHeaderItem (for more information have a look at the javadoc)
+
+To change the cache headers override the method *protected void applyPageCacheHeader()* of the PushHeaderItem
\ No newline at end of file