Uploaded image for project: 'Cocoon'
  1. Cocoon
  2. COCOON-1266

[PATCH] Resource reader fails to add HTTP headers

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1.5
    • 2.1.10, 2.2
    • - Components: Sitemap
    • None
    • Operating System: All
      Platform: All
    • 31243
    • Patch available

    Description

      The resource reader does not add Last-Modified and Expires headers when serving
      resources from the cocoon cache. This leads to unneccessary request from
      clients. I think setting the headers in setup() instead of generate() should
      fix this problem because generate will only be called for resources not already
      in the cache.
      Fixing this will trigger another bug introduced with patch #14048. This causes
      all resources to be deliverd with a Vary:Host header unless an expiration time
      has been set on the reader (which you usually won´t do). This causes IE to read
      the resource again and again. The correct solution is to add an Expires header
      with a value of 0, but only if configured!

      I prepared a small patch (against 2.1.5) to fix both problems:

      diff -u -r1.1.1.3 -r1.5
      --- ResourceReader.java 10 Jun 2004 11:23:49 -0000 1.1.1.3
      +++ ResourceReader.java 10 Jun 2004 12:36:49 -0000 1.5
      @@ -118,6 +118,15 @@
       
               try {
                   inputSource = resolver.resolveURI(src);
      +
      + if (expires >= 0) {
      + response.setDateHeader("Expires", expires > 0 ?
      System.currentTimeMillis() + expires : 0);
      + }
      +
      + long lastModified = getLastModified();
      + if (lastModified > 0) {
      + response.setDateHeader("Last-Modified",
      lastModified);
      + }
               }
               catch (SourceException se) {
                   throw SourceUtil.handle("Error during resolving of '" + src
      + "'.", se);
      @@ -255,18 +264,6 @@
            */
           public void generate() throws IOException, ProcessingException {
               try {
      - if (expires > 0) {
      - response.setDateHeader("Expires", System.currentTimeMillis() +
      expires);
      - }
      - else {
      - response.addHeader("Vary", "Host");
      - }
      -
      - long lastModified = getLastModified();
      - if (lastModified > 0) {
      - response.setDateHeader("Last-Modified", lastModified);
      - }
      -
                   try {
                       inputStream = inputSource.getInputStream();
                   }
      @@ -316,3 +313,4 @@
           }
       
       }

      Attachments

        Issue Links

          Activity

            People

              antonio Antonio Gallardo Rivera
              martin.kuck@multi-m.de Martin Kuck
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: