You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by "David Crossley (JIRA)" <ji...@apache.org> on 2006/03/01 08:02:39 UTC

[jira] Updated: (COCOON-1266) [PATCH] Resource reader fails to add HTTP headers

     [ http://issues.apache.org/jira/browse/COCOON-1266?page=all ]

David Crossley updated COCOON-1266:
-----------------------------------

    Bugzilla Id:   (was: 31243)
     Other Info: [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 @@
     }
 
 }

  was:
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 @@
     }
 
 }


> [PATCH] Resource reader fails to add HTTP headers
> -------------------------------------------------
>
>          Key: COCOON-1266
>          URL: http://issues.apache.org/jira/browse/COCOON-1266
>      Project: Cocoon
>         Type: Bug
>   Components: - Components: Sitemap
>     Versions: 2.1.5
>  Environment: Operating System: All
> Platform: All
>     Reporter: Martin Kuck
>     Assignee: Cocoon Developers Team

>
> 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 @@
>      }
>  
>  }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira