View | Details | Raw Unified | Return to bug 45906
Collapse All | Expand All

(-)java/org/apache/catalina/servlets/DefaultServlet.java (-24 / +6 lines)
Lines 578-601 Link Here
578
578
579
579
580
    /**
580
    /**
581
     * Get the ETag associated with a file.
582
     *
583
     * @param resourceAttributes The resource information
584
     */
585
    protected String getETag(ResourceAttributes resourceAttributes) {
586
        String result = null;
587
        if ((result = resourceAttributes.getETag(true)) != null) {
588
            return result;
589
        } else if ((result = resourceAttributes.getETag()) != null) {
590
            return result;
591
        } else {
592
            return "W/\"" + resourceAttributes.getContentLength() + "-"
593
                + resourceAttributes.getLastModified() + "\"";
594
        }
595
    }
596
597
598
    /**
599
     * URL rewriter.
581
     * URL rewriter.
600
     *
582
     *
601
     * @param path Path which has to be rewiten
583
     * @param path Path which has to be rewiten
Lines 733-739 Link Here
733
            ranges = parseRange(request, response, cacheEntry.attributes);
715
            ranges = parseRange(request, response, cacheEntry.attributes);
734
716
735
            // ETag header
717
            // ETag header
736
            response.setHeader("ETag", getETag(cacheEntry.attributes));
718
            response.setHeader("ETag", cacheEntry.attributes.getETag());
737
719
738
            // Last-Modified header
720
            // Last-Modified header
739
            response.setHeader("Last-Modified",
721
            response.setHeader("Last-Modified",
Lines 979-985 Link Here
979
                ;
961
                ;
980
            }
962
            }
981
963
982
            String eTag = getETag(resourceAttributes);
964
            String eTag = resourceAttributes.getETag();
983
            long lastModified = resourceAttributes.getLastModified();
965
            long lastModified = resourceAttributes.getLastModified();
984
966
985
            if (headerValueTime == (-1L)) {
967
            if (headerValueTime == (-1L)) {
Lines 1531-1537 Link Here
1531
                                 ResourceAttributes resourceAttributes)
1513
                                 ResourceAttributes resourceAttributes)
1532
        throws IOException {
1514
        throws IOException {
1533
1515
1534
        String eTag = getETag(resourceAttributes);
1516
        String eTag = resourceAttributes.getETag();
1535
        String headerValue = request.getHeader("If-Match");
1517
        String headerValue = request.getHeader("If-Match");
1536
        if (headerValue != null) {
1518
        if (headerValue != null) {
1537
            if (headerValue.indexOf('*') == -1) {
1519
            if (headerValue.indexOf('*') == -1) {
Lines 1587-1593 Link Here
1587
                    // The entity has not been modified since the date
1569
                    // The entity has not been modified since the date
1588
                    // specified by the client. This is not an error case.
1570
                    // specified by the client. This is not an error case.
1589
                    response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
1571
                    response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
1590
                    response.setHeader("ETag", getETag(resourceAttributes));
1572
                    response.setHeader("ETag", resourceAttributes.getETag());
1591
1573
1592
                    return false;
1574
                    return false;
1593
                }
1575
                }
Lines 1615-1621 Link Here
1615
                                     ResourceAttributes resourceAttributes)
1597
                                     ResourceAttributes resourceAttributes)
1616
        throws IOException {
1598
        throws IOException {
1617
1599
1618
        String eTag = getETag(resourceAttributes);
1600
        String eTag = resourceAttributes.getETag();
1619
        String headerValue = request.getHeader("If-None-Match");
1601
        String headerValue = request.getHeader("If-None-Match");
1620
        if (headerValue != null) {
1602
        if (headerValue != null) {
1621
1603
Lines 1645-1651 Link Here
1645
                if ( ("GET".equals(request.getMethod()))
1627
                if ( ("GET".equals(request.getMethod()))
1646
                     || ("HEAD".equals(request.getMethod())) ) {
1628
                     || ("HEAD".equals(request.getMethod())) ) {
1647
                    response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
1629
                    response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
1648
                    response.setHeader("ETag", getETag(resourceAttributes));
1630
                    response.setHeader("ETag", eTag);
1649
1631
1650
                    return false;
1632
                    return false;
1651
                } else {
1633
                } else {
(-)java/org/apache/catalina/servlets/WebdavServlet.java (-2 / +2 lines)
Lines 2131-2137 Link Here
2131
                                               contentType);
2131
                                               contentType);
2132
                }
2132
                }
2133
                generatedXML.writeProperty(null, "getetag",
2133
                generatedXML.writeProperty(null, "getetag",
2134
                                           getETag(cacheEntry.attributes));
2134
                                           cacheEntry.attributes.getETag());
2135
                generatedXML.writeElement(null, "resourcetype",
2135
                generatedXML.writeElement(null, "resourcetype",
2136
                                          XMLWriter.NO_CONTENT);
2136
                                          XMLWriter.NO_CONTENT);
2137
            } else {
2137
            } else {
Lines 2257-2263 Link Here
2257
                        propertiesNotFound.addElement(property);
2257
                        propertiesNotFound.addElement(property);
2258
                    } else {
2258
                    } else {
2259
                        generatedXML.writeProperty
2259
                        generatedXML.writeProperty
2260
                            (null, "getetag", getETag(cacheEntry.attributes));
2260
                            (null, "getetag", cacheEntry.attributes.getETag());
2261
                    }
2261
                    }
2262
                } else if (property.equals("getlastmodified")) {
2262
                } else if (property.equals("getlastmodified")) {
2263
                    if (cacheEntry.context != null) {
2263
                    if (cacheEntry.context != null) {
(-)java/org/apache/naming/resources/ResourceAttributes.java (-17 / +37 lines)
Lines 123-128 Link Here
123
    
123
    
124
    
124
    
125
    /**
125
    /**
126
     * ETag.
127
     */
128
    public static final String ALTERNATE_ETAG = "etag";
129
    
130
    
131
    /**
126
     * Collection type.
132
     * Collection type.
127
     */
133
     */
128
    public static final String COLLECTION_TYPE = "<collection/>";
134
    public static final String COLLECTION_TYPE = "<collection/>";
Lines 704-723 Link Here
704
    /**
710
    /**
705
     * Get ETag.
711
     * Get ETag.
706
     * 
712
     * 
707
     * @return Weak ETag
713
     * @return strong ETag if available, else weak ETag.
708
     */
714
     */
709
    public String getETag() {
715
    public String getETag() {
710
        return getETag(false);
711
    }
712
713
714
    /**
715
     * Get ETag.
716
     * 
717
     * @param strong If true, the strong ETag will be returned
718
     * @return ETag
719
     */
720
    public String getETag(boolean strong) {
721
        String result = null;
716
        String result = null;
722
        if (attributes != null) {
717
        if (attributes != null) {
723
            Attribute attribute = attributes.get(ETAG);
718
            Attribute attribute = attributes.get(ETAG);
Lines 729-744 Link Here
729
                }
724
                }
730
            }
725
            }
731
        }
726
        }
732
        if (strong) {
727
        if (result == null) {
728
          if (strongETag != null) {
733
            // The strong ETag must always be calculated by the resources
729
            // The strong ETag must always be calculated by the resources
734
            result = strongETag;
730
            result = strongETag;
735
        } else {
731
          } else {
736
            // The weakETag is contentLenght + lastModified
732
            // The weakETag is contentLenght + lastModified
737
            if (weakETag == null) {
733
            if (weakETag == null) {
738
                weakETag = "W/\"" + getContentLength() + "-" 
734
                long contentLength = getContentLength();
739
                    + getLastModified() + "\"";
735
                long lastModified = getLastModified();
736
                if ((contentLength >= 0) || (lastModified >= 0)) {
737
                  weakETag = "W/\"" + contentLength + "-" 
738
                      + lastModified + "\"";
739
                }
740
            }
740
            }
741
            result = weakETag;
741
            result = weakETag;
742
          }
742
        }
743
        }
743
        return result;
744
        return result;
744
    }
745
    }
Lines 747-753 Link Here
747
    /**
748
    /**
748
     * Set strong ETag.
749
     * Set strong ETag.
749
     */
750
     */
750
    public void setETag(String eTag) {
751
    public void setStrongETag(String eTag) {
751
        this.strongETag = eTag;
752
        this.strongETag = eTag;
752
        if (attributes != null)
753
        if (attributes != null)
753
            attributes.put(ETAG, eTag);
754
            attributes.put(ETAG, eTag);
Lines 810-815 Link Here
810
              long contentLength = getContentLength();
811
              long contentLength = getContentLength();
811
              if (contentLength < 0) return null;
812
              if (contentLength < 0) return null;
812
              return new BasicAttribute(ALTERNATE_CONTENT_LENGTH, new Long(contentLength));
813
              return new BasicAttribute(ALTERNATE_CONTENT_LENGTH, new Long(contentLength));
814
            } else if (attrID.equals(ETAG)) {
815
              String etag = getETag();
816
              if (etag == null) return null;
817
              return new BasicAttribute(ETAG, etag);
818
            } else if (attrID.equals(ALTERNATE_ETAG)) {
819
              String etag = getETag();
820
              if (etag == null) return null;
821
              return new BasicAttribute(ALTERNATE_ETAG, etag);
813
            }
822
            }
814
        } else {
823
        } else {
815
            return attributes.get(attrID);
824
            return attributes.get(attrID);
Lines 893-898 Link Here
893
                attributes.addElement(new BasicAttribute(CONTENT_LENGTH, contentLengthLong));
902
                attributes.addElement(new BasicAttribute(CONTENT_LENGTH, contentLengthLong));
894
                attributes.addElement(new BasicAttribute(ALTERNATE_CONTENT_LENGTH, contentLengthLong));
903
                attributes.addElement(new BasicAttribute(ALTERNATE_CONTENT_LENGTH, contentLengthLong));
895
            }
904
            }
905
            String etag = getETag();
906
            if (etag != null) {
907
                attributes.addElement(new BasicAttribute(ETAG, etag));
908
                attributes.addElement(new BasicAttribute(ALTERNATE_ETAG, etag));
909
            }
896
            return new RecyclableNamingEnumeration(attributes);
910
            return new RecyclableNamingEnumeration(attributes);
897
        } else {
911
        } else {
898
            return attributes.getAll();
912
            return attributes.getAll();
Lines 929-934 Link Here
929
                attributeIDs.addElement(CONTENT_LENGTH);
943
                attributeIDs.addElement(CONTENT_LENGTH);
930
                attributeIDs.addElement(ALTERNATE_CONTENT_LENGTH);
944
                attributeIDs.addElement(ALTERNATE_CONTENT_LENGTH);
931
            }
945
            }
946
            String etag = getETag();
947
            if (etag != null) {
948
                attributeIDs.addElement(ETAG);
949
                attributeIDs.addElement(ALTERNATE_ETAG);
950
            }
932
            return new RecyclableNamingEnumeration(attributeIDs);
951
            return new RecyclableNamingEnumeration(attributeIDs);
933
        } else {
952
        } else {
934
            return attributes.getIDs();
953
            return attributes.getIDs();
Lines 947-952 Link Here
947
            if (getName() != null) size++;
966
            if (getName() != null) size++;
948
            if (getResourceType() != null) size += 2;
967
            if (getResourceType() != null) size += 2;
949
            if (getContentLength() >= 0) size += 2;
968
            if (getContentLength() >= 0) size += 2;
969
            if (getETag() != null) size += 2;
950
            return size;
970
            return size;
951
        } else {
971
        } else {
952
            return attributes.size();
972
            return attributes.size();

Return to bug 45906