tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r700125 - in /tomcat/trunk/java/org/apache: catalina/servlets/DefaultServlet.java catalina/servlets/WebdavServlet.java naming/resources/ResourceAttributes.java
Date Mon, 29 Sep 2008 13:24:37 GMT
Author: markt
Date: Mon Sep 29 06:24:36 2008
New Revision: 700125

URL: http://svn.apache.org/viewvc?rev=700125&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=45906
Improve ResourceAttributes ETag handling.
Patch provided by Chris Hubick

Modified:
    tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java
    tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java
    tomcat/trunk/java/org/apache/naming/resources/ResourceAttributes.java

Modified: tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java?rev=700125&r1=700124&r2=700125&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java Mon Sep 29 06:24:36
2008
@@ -578,24 +578,6 @@
 
 
     /**
-     * Get the ETag associated with a file.
-     *
-     * @param resourceAttributes The resource information
-     */
-    protected String getETag(ResourceAttributes resourceAttributes) {
-        String result = null;
-        if ((result = resourceAttributes.getETag(true)) != null) {
-            return result;
-        } else if ((result = resourceAttributes.getETag()) != null) {
-            return result;
-        } else {
-            return "W/\"" + resourceAttributes.getContentLength() + "-"
-                + resourceAttributes.getLastModified() + "\"";
-        }
-    }
-
-
-    /**
      * URL rewriter.
      *
      * @param path Path which has to be rewiten
@@ -733,7 +715,7 @@
             ranges = parseRange(request, response, cacheEntry.attributes);
 
             // ETag header
-            response.setHeader("ETag", getETag(cacheEntry.attributes));
+            response.setHeader("ETag", cacheEntry.attributes.getETag());
 
             // Last-Modified header
             response.setHeader("Last-Modified",
@@ -978,7 +960,7 @@
                 // Ignore
             }
 
-            String eTag = getETag(resourceAttributes);
+            String eTag = resourceAttributes.getETag();
             long lastModified = resourceAttributes.getLastModified();
 
             if (headerValueTime == (-1L)) {
@@ -1532,7 +1514,7 @@
                                  ResourceAttributes resourceAttributes)
         throws IOException {
 
-        String eTag = getETag(resourceAttributes);
+        String eTag = resourceAttributes.getETag();
         String headerValue = request.getHeader("If-Match");
         if (headerValue != null) {
             if (headerValue.indexOf('*') == -1) {
@@ -1588,7 +1570,7 @@
                     // The entity has not been modified since the date
                     // specified by the client. This is not an error case.
                     response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
-                    response.setHeader("ETag", getETag(resourceAttributes));
+                    response.setHeader("ETag", resourceAttributes.getETag());
 
                     return false;
                 }
@@ -1616,7 +1598,7 @@
                                      ResourceAttributes resourceAttributes)
         throws IOException {
 
-        String eTag = getETag(resourceAttributes);
+        String eTag = resourceAttributes.getETag();
         String headerValue = request.getHeader("If-None-Match");
         if (headerValue != null) {
 
@@ -1646,7 +1628,7 @@
                 if ( ("GET".equals(request.getMethod()))
                      || ("HEAD".equals(request.getMethod())) ) {
                     response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
-                    response.setHeader("ETag", getETag(resourceAttributes));
+                    response.setHeader("ETag", eTag);
 
                     return false;
                 } else {

Modified: tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java?rev=700125&r1=700124&r2=700125&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/servlets/WebdavServlet.java Mon Sep 29 06:24:36
2008
@@ -2132,7 +2132,7 @@
                                                contentType);
                 }
                 generatedXML.writeProperty(null, "getetag",
-                                           getETag(cacheEntry.attributes));
+                                           cacheEntry.attributes.getETag());
                 generatedXML.writeElement(null, "resourcetype",
                                           XMLWriter.NO_CONTENT);
             } else {
@@ -2258,7 +2258,7 @@
                         propertiesNotFound.addElement(property);
                     } else {
                         generatedXML.writeProperty
-                            (null, "getetag", getETag(cacheEntry.attributes));
+                            (null, "getetag", cacheEntry.attributes.getETag());
                     }
                 } else if (property.equals("getlastmodified")) {
                     if (cacheEntry.context != null) {

Modified: tomcat/trunk/java/org/apache/naming/resources/ResourceAttributes.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/naming/resources/ResourceAttributes.java?rev=700125&r1=700124&r2=700125&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/naming/resources/ResourceAttributes.java (original)
+++ tomcat/trunk/java/org/apache/naming/resources/ResourceAttributes.java Mon Sep 29 06:24:36
2008
@@ -123,6 +123,12 @@
     
     
     /**
+     * ETag.
+     */
+    public static final String ALTERNATE_ETAG = "etag";
+    
+    
+    /**
      * Collection type.
      */
     public static final String COLLECTION_TYPE = "<collection/>";
@@ -704,20 +710,9 @@
     /**
      * Get ETag.
      * 
-     * @return Weak ETag
+     * @return strong ETag if available, else weak ETag.
      */
     public String getETag() {
-        return getETag(false);
-    }
-
-
-    /**
-     * Get ETag.
-     * 
-     * @param strong If true, the strong ETag will be returned
-     * @return ETag
-     */
-    public String getETag(boolean strong) {
         String result = null;
         if (attributes != null) {
             Attribute attribute = attributes.get(ETAG);
@@ -729,16 +724,22 @@
                 }
             }
         }
-        if (strong) {
-            // The strong ETag must always be calculated by the resources
-            result = strongETag;
-        } else {
-            // The weakETag is contentLenght + lastModified
-            if (weakETag == null) {
-                weakETag = "W/\"" + getContentLength() + "-" 
-                    + getLastModified() + "\"";
+        if (result == null) {
+            if (strongETag != null) {
+                // The strong ETag must always be calculated by the resources
+                result = strongETag;
+            } else {
+                // The weakETag is contentLength + lastModified
+                if (weakETag == null) {
+                    long contentLength = getContentLength();
+                    long lastModified = getLastModified();
+                    if ((contentLength >= 0) || (lastModified >= 0)) {
+                        weakETag = "W/\"" + contentLength + "-" 
+                        + lastModified + "\"";
+                    }
+                }
+                result = weakETag;
             }
-            result = weakETag;
         }
         return result;
     }
@@ -810,6 +811,14 @@
               long contentLength = getContentLength();
               if (contentLength < 0) return null;
               return new BasicAttribute(ALTERNATE_CONTENT_LENGTH, new Long(contentLength));
+            } else if (attrID.equals(ETAG)) {
+              String etag = getETag();
+              if (etag == null) return null;
+              return new BasicAttribute(ETAG, etag);
+            } else if (attrID.equals(ALTERNATE_ETAG)) {
+              String etag = getETag();
+              if (etag == null) return null;
+              return new BasicAttribute(ALTERNATE_ETAG, etag);
             }
         } else {
             return attributes.get(attrID);
@@ -893,6 +902,11 @@
                 attributes.addElement(new BasicAttribute(CONTENT_LENGTH, contentLengthLong));
                 attributes.addElement(new BasicAttribute(ALTERNATE_CONTENT_LENGTH, contentLengthLong));
             }
+            String etag = getETag();
+            if (etag != null) {
+                attributes.addElement(new BasicAttribute(ETAG, etag));
+                attributes.addElement(new BasicAttribute(ALTERNATE_ETAG, etag));
+            }
             return new RecyclableNamingEnumeration(attributes);
         } else {
             return attributes.getAll();
@@ -929,6 +943,11 @@
                 attributeIDs.addElement(CONTENT_LENGTH);
                 attributeIDs.addElement(ALTERNATE_CONTENT_LENGTH);
             }
+            String etag = getETag();
+            if (etag != null) {
+                attributeIDs.addElement(ETAG);
+                attributeIDs.addElement(ALTERNATE_ETAG);
+            }
             return new RecyclableNamingEnumeration(attributeIDs);
         } else {
             return attributes.getIDs();
@@ -947,6 +966,7 @@
             if (getName() != null) size++;
             if (getResourceType() != null) size += 2;
             if (getContentLength() >= 0) size += 2;
+            if (getETag() != null) size += 2;
             return size;
         } else {
             return attributes.size();



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message