Allow GWT *.nocache.js to be cached forever if ?content= is supplied

This trick permits the host page to rewrite its <script> reference
to the *.nocache.js to include the SHA-1 or MD-5 hash of the file
content.  By doing so we can allow the browser or edge proxy to
cache the file indefinitely, as the host page would use another URL
if the nocache file was regenerated on a different compilation.

Since the host page for Gerrit (our primary customer) is smaller
than the corresponding *.nocache.js, and the host page can be sent
with gzip while few browsers support gzip encoding on JavaScript,
we can reduce the load time for each new site visit by fetching the
larger content from local cache.

Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/pom.xml b/pom.xml
index 587f8ab..49a41ad 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,7 +21,7 @@
   <groupId>gwtexpui</groupId>
   <artifactId>gwtexpui</artifactId>
   <packaging>jar</packaging>
-  <version>1.0.2</version>
+  <version>1.0.3</version>
   <name>gwtexpui</name>
   <description>Extended UI tools for GWT</description>
   <url>http://android.git.kernel.org/?p=tools/gwtexpui.git</url>
diff --git a/src/main/java/com/google/gwtexpui/server/CacheControlFilter.java b/src/main/java/com/google/gwtexpui/server/CacheControlFilter.java
index 228495d..e389d23 100644
--- a/src/main/java/com/google/gwtexpui/server/CacheControlFilter.java
+++ b/src/main/java/com/google/gwtexpui/server/CacheControlFilter.java
@@ -60,7 +60,7 @@
     final HttpServletResponse rsp = (HttpServletResponse) srsp;
     final String pathInfo = pathInfo(req);
 
-    if (cacheForever(pathInfo)) {
+    if (cacheForever(pathInfo, req)) {
       final long now = System.currentTimeMillis();
       rsp.setHeader("Cache-Control", "max-age=31536000,public");
       rsp.setDateHeader("Expires", now + 31536000000L);
@@ -76,7 +76,8 @@
     chain.doFilter(req, rsp);
   }
 
-  private static boolean cacheForever(final String pathInfo) {
+  private static boolean cacheForever(final String pathInfo,
+      final HttpServletRequest req) {
     if (pathInfo.endsWith(".cache.html")) {
       return true;
     } else if (pathInfo.endsWith(".cache.gif")) {
@@ -89,6 +90,9 @@
       return true;
     } else if (pathInfo.endsWith(".cache.swf")) {
       return true;
+    } else if (pathInfo.endsWith(".nocache.js")) {
+      final String v = req.getParameter("content");
+      return v != null && v.length() > 20;
     }
     return false;
   }