You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Kai Mütz <km...@web.de> on 2006/03/22 13:58:42 UTC

Strange response.setHeader behaviour in custom reader (Cocoon 2.1.8)

Hi,

we use a custom reader component similar to ResourceReader which makes use
of HTTP Headers. In addition to the settings in ResourceReader I want to
disable client caching by setting the "Cache-Control" header (like
HTTPCacheAction does). Thus I have extended the seupHeaders() method to:

private void setupHeaders() {
    Response response = ObjectModelHelper.getResponse(this.objectModel);
    final long MILLISECONDS_PER_SECOND = 1000L;
    Calendar calendar = Calendar.getInstance(DateUtils.UTC_TIME_ZONE);
    String formattedCal = this.formatter.format(calendar);
    if (this.expires > MILLISECONDS_PER_SECOND) {
        calendar.setTimeInMillis(calendar.getTimeInMillis() + this.expires);
        response.setHeader("Expires", this.formatter.format(calendar));
        response.setHeader("Cache-Control", "max-age="
                + Long.toString(this.expires / MILLISECONDS_PER_SECOND));
    } else if (0 <= this.expires) {
        response.setHeader("Expires", formattedCal);
        response.setHeader("Cache-Control", "max-age=0");
    } else if (this.expires == -1) {
        response.setHeader("Expires", "Thu, 01 Jan 2000 00:00:00 GMT");
        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
    }
}

The first two "ifs" are working correctly. But in case of disabled cache
(expires == -1) the "Expires" and "Cache-Control" headers are either not set
or overwritten elsewhere. The "Pragma" header ist set correctly! This is
very strange for me. Any ideas?

Thanks,
Kai


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: Strange response.setHeader behaviour in custom reader (Cocoon 2.1.8)

Posted by Kai Mütz <km...@web.de>.
But I call the reader by an "normal" (external) request. Furthermore if I
call the HTTPCacheAction before the reader it works.

<map:actions>
	<map:action name="no-header-cache"
src="org.apache.cocoon.acting.HttpCacheAction"/>
</map:actions>
...
<map:pipeline type="caching">
	<map:match pattern="*.png">
	    <map:act type="no-header-cache"/>
	    <map:read type="binary-resource" mime-type="image/png"
src="{global:xmldb-uri}/bin/{1}.png"/>
	</map:match>
</map:pipeline>

> -----Original Message-----
> From: users-return-86090-kmuetz=web.de@cocoon.apache.org
> [mailto:users-return-86090-kmuetz=web.de@cocoon.apache.org]On Behalf Of
> Bertrand Delacretaz
> Sent: Friday, March 24, 2006 10:39 AM
> To: users@cocoon.apache.org
> Subject: Re: Strange response.setHeader behaviour in custom reader
> (Cocoon 2.1.8)
>
>
> Le 22 mars 06 à 13:58, Kai Mütz a écrit :
>
> > ....The first two "ifs" are working correctly. But in case of
> > disabled cache
> > (expires == -1) the "Expires" and "Cache-Control" headers are
> > either not set
> > or overwritten elsewhere..
>
> This might have to do with http://issues.apache.org/jira/browse/
> COCOON-1619
>
> -Bertrand


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Strange response.setHeader behaviour in custom reader (Cocoon 2.1.8)

Posted by Bertrand Delacretaz <bd...@apache.org>.
Le 22 mars 06 à 13:58, Kai Mütz a écrit :

> ....The first two "ifs" are working correctly. But in case of  
> disabled cache
> (expires == -1) the "Expires" and "Cache-Control" headers are  
> either not set
> or overwritten elsewhere..

This might have to do with http://issues.apache.org/jira/browse/ 
COCOON-1619

-Bertrand

RE: Strange response.setHeader behaviour in custom reader (Cocoon 2.1.8)

Posted by Kai Mütz <km...@web.de>.
Has anybody observed a similar problem and can help?

Thanks in advance,
Kai

> -----Original Message-----
> From: users-return-86029-kmuetz=web.de@cocoon.apache.org
> [mailto:users-return-86029-kmuetz=web.de@cocoon.apache.org]On Behalf Of
> Kai Mütz
> Sent: Wednesday, March 22, 2006 1:59 PM
> To: users@cocoon.apache.org
> Subject: Strange response.setHeader behaviour in custom reader (Cocoon
> 2.1.8)
>
>
> Hi,
>
> we use a custom reader component similar to ResourceReader which makes use
> of HTTP Headers. In addition to the settings in ResourceReader I want to
> disable client caching by setting the "Cache-Control" header (like
> HTTPCacheAction does). Thus I have extended the seupHeaders() method to:
>
> private void setupHeaders() {
>     Response response = ObjectModelHelper.getResponse(this.objectModel);
>     final long MILLISECONDS_PER_SECOND = 1000L;
>     Calendar calendar = Calendar.getInstance(DateUtils.UTC_TIME_ZONE);
>     String formattedCal = this.formatter.format(calendar);
>     if (this.expires > MILLISECONDS_PER_SECOND) {
>         calendar.setTimeInMillis(calendar.getTimeInMillis() +
> this.expires);
>         response.setHeader("Expires", this.formatter.format(calendar));
>         response.setHeader("Cache-Control", "max-age="
>                 + Long.toString(this.expires / MILLISECONDS_PER_SECOND));
>     } else if (0 <= this.expires) {
>         response.setHeader("Expires", formattedCal);
>         response.setHeader("Cache-Control", "max-age=0");
>     } else if (this.expires == -1) {
>         response.setHeader("Expires", "Thu, 01 Jan 2000 00:00:00 GMT");
>         response.setHeader("Cache-Control", "no-cache");
>         response.setHeader("Pragma", "no-cache");
>     }
> }
>
> The first two "ifs" are working correctly. But in case of disabled cache
> (expires == -1) the "Expires" and "Cache-Control" headers are
> either not set
> or overwritten elsewhere. The "Pragma" header ist set correctly! This is
> very strange for me. Any ideas?
>
> Thanks,
> Kai
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org