tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r708151 - in /tomcat/tc6.0.x/trunk: STATUS.txt java/org/apache/catalina/servlets/DefaultServlet.java java/org/apache/catalina/servlets/WebdavServlet.java java/org/apache/naming/resources/ResourceAttributes.java webapps/docs/changelog.xml
Date Mon, 27 Oct 2008 11:50:45 GMT
Author: markt
Date: Mon Oct 27 04:50:44 2008
New Revision: 708151

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

Modified:
    tomcat/tc6.0.x/trunk/STATUS.txt
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/servlets/DefaultServlet.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/servlets/WebdavServlet.java
    tomcat/tc6.0.x/trunk/java/org/apache/naming/resources/ResourceAttributes.java
    tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml

Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=708151&r1=708150&r2=708151&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Mon Oct 27 04:50:44 2008
@@ -166,14 +166,6 @@
         }
         StringBuffer sb = new StringBuffer();
 
-* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=45906
-  Improve ETag handling in ResourceAttributes
-  Patch provided by Chris Hubick
-  http://svn.apache.org/viewvc?rev=700125&view=rev
-  Note: Deleted getETag(boolean) method to remain but deprecated
-  +1: markt, remm (I was -1 originally, but it may not be so bad),fhanik
-  -1: 
-
 * Fix some thread safety issues.
   Deprecate (rather than delete) any deleted code that isn't already deprecated
   http://svn.apache.org/viewvc?rev=699714&view=rev (previous patch)

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/servlets/DefaultServlet.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/servlets/DefaultServlet.java?rev=708151&r1=708150&r2=708151&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/servlets/DefaultServlet.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/servlets/DefaultServlet.java Mon Oct 27
04:50:44 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",
@@ -979,7 +961,7 @@
                 ;
             }
 
-            String eTag = getETag(resourceAttributes);
+            String eTag = resourceAttributes.getETag();
             long lastModified = resourceAttributes.getLastModified();
 
             if (headerValueTime == (-1L)) {
@@ -1531,7 +1513,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) {
@@ -1587,7 +1569,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;
                 }
@@ -1615,7 +1597,7 @@
                                      ResourceAttributes resourceAttributes)
         throws IOException {
 
-        String eTag = getETag(resourceAttributes);
+        String eTag = resourceAttributes.getETag();
         String headerValue = request.getHeader("If-None-Match");
         if (headerValue != null) {
 
@@ -1645,7 +1627,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/tc6.0.x/trunk/java/org/apache/catalina/servlets/WebdavServlet.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/servlets/WebdavServlet.java?rev=708151&r1=708150&r2=708151&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/servlets/WebdavServlet.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/servlets/WebdavServlet.java Mon Oct 27 04:50:44
2008
@@ -2131,7 +2131,7 @@
                                                contentType);
                 }
                 generatedXML.writeProperty(null, "getetag",
-                                           getETag(cacheEntry.attributes));
+                                           cacheEntry.attributes.getETag());
                 generatedXML.writeElement(null, "resourcetype",
                                           XMLWriter.NO_CONTENT);
             } else {
@@ -2257,7 +2257,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/tc6.0.x/trunk/java/org/apache/naming/resources/ResourceAttributes.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/naming/resources/ResourceAttributes.java?rev=708151&r1=708150&r2=708151&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/naming/resources/ResourceAttributes.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/naming/resources/ResourceAttributes.java Mon Oct
27 04:50:44 2008
@@ -123,6 +123,12 @@
     
     
     /**
+     * ETag.
+     */
+    public static final String ALTERNATE_ETAG = "etag";
+    
+    
+    /**
      * Collection type.
      */
     public static final String COLLECTION_TYPE = "<collection/>";
@@ -704,43 +710,50 @@
     /**
      * Get ETag.
      * 
-     * @return Weak ETag
+     * @return strong ETag if available, else weak ETag. 
      */
     public String getETag() {
-        return getETag(false);
+        String result = null;
+        if (attributes != null) {
+            Attribute attribute = attributes.get(ETAG);
+            if (attribute != null) {
+                try {
+                    result = attribute.get().toString();
+                } catch (NamingException e) {
+                    ; // No value for the attribute
+                }
+            }
+        }
+        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;
+            }
+        } 
+        return result;
     }
 
 
     /**
      * Get ETag.
      * 
-     * @param strong If true, the strong ETag will be returned
-     * @return ETag
+     * @param strong Ignored
+     * @return strong ETag if available, else weak ETag.
+     * @deprecated
      */
     public String getETag(boolean strong) {
-        if (strong) {
-            // The strong ETag must always be calculated by the resources
-            if (strongETag != null)
-                return strongETag;
-            if (attributes != null) {
-                Attribute attribute = attributes.get(ETAG);
-                if (attribute != null) {
-                    try {
-                        strongETag = attribute.get().toString();
-                    } catch (NamingException e) {
-                        ; // No value for the attribute
-                    }
-                }
-            }
-            return strongETag;
-        } else {
-            // The weakETag is contentLenght + lastModified
-            if (weakETag == null) {
-                weakETag = "W/\"" + getContentLength() + "-" 
-                    + getLastModified() + "\"";
-            }
-            return weakETag;
-        }
+        return getETag();
     }
 
 
@@ -807,9 +820,17 @@
                 if (contentLength < 0) return null;
                 return new BasicAttribute(CONTENT_LENGTH, new Long(contentLength));
             } else if (attrID.equals(ALTERNATE_CONTENT_LENGTH)) {
-              long contentLength = getContentLength();
-              if (contentLength < 0) return null;
-              return new BasicAttribute(ALTERNATE_CONTENT_LENGTH, new Long(contentLength));
+                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 +914,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 +955,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 +978,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();

Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=708151&r1=708150&r2=708151&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Mon Oct 27 04:50:44 2008
@@ -93,6 +93,10 @@
         <bug>45823</bug>: Log missing request headers as '-' not 'null'. Based
         on a patch by Per Landberg. (markt)
       </fix>
+      <fix>
+        <bug>45906</bug>: Further ETag handling improvements. Patch provided
by
+        Chris Hubick. (markt)
+      </fix>
       <add>
         Add the CombinedRealm that enables authentication to be attempted
         against multiple realms. (markt) 



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


Mime
View raw message