You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Yoryos <va...@gmail.com> on 2010/07/23 11:10:30 UTC

setHeader vs addHeader problem

Hello
looking at HttpServletResponse
javadoc<http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpServletResponse.html>
I
can understand that the difference between setHeader and addHeader is that
the first one overrides previous setted one (if any) and the second one just
ads the new value to an existing one (or create an new one if it doesn't
exists). I use the second in order to add to my responses Cache-Control
headers.

With something like:
response.addHeader('Cache-Control', 'public');
response.addHeader('Cache-Control', 'stale-if-error=xxx');
response.addHeader('Cache-Control', 'max-age=xxx');
response.addHeader('Cache-Control', 's-maxage=xxx');

I would expect an one line response header like Cache-Control: public,
stale-if-error=xxx, max-age=xxx, s-maxage=xxx but what I get is three
Cache-Control headers:

*$ telnet localhost 80*
*HEAD / HTTP/1.1*
*Host: some.host.com\n\n*

HTTP/1.1 200 OK
Cache-Control: stale-if-error=172800
Cache-Control: public
Cache-Control: max-age=60
Cache-Control: s-maxage=40
ETag: "custom-etag"
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 23 Jul 2010 09:00:49 GMT
Server: CustomServerName

Is this the expected behavior? I've never seen such a response header
before. Should I issue a bug?

Re: setHeader vs addHeader problem

Posted by Yoryos <va...@gmail.com>.
I forgot to mention that I use Tomcat v6.0.20

On Fri, Jul 23, 2010 at 12:10, Yoryos <va...@gmail.com> wrote:

> Hello
> looking at HttpServletResponse javadoc<http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpServletResponse.html> I
> can understand that the difference between setHeader and addHeader is that
> the first one overrides previous setted one (if any) and the second one just
> ads the new value to an existing one (or create an new one if it doesn't
> exists). I use the second in order to add to my responses Cache-Control
> headers.
>
> With something like:
> response.addHeader('Cache-Control', 'public');
> response.addHeader('Cache-Control', 'stale-if-error=xxx');
> response.addHeader('Cache-Control', 'max-age=xxx');
> response.addHeader('Cache-Control', 's-maxage=xxx');
>
> I would expect an one line response header like Cache-Control: public,
> stale-if-error=xxx, max-age=xxx, s-maxage=xxx but what I get is three
> Cache-Control headers:
>
> *$ telnet localhost 80*
> *HEAD / HTTP/1.1*
> *Host: some.host.com\n\n*
>
> HTTP/1.1 200 OK
> Cache-Control: stale-if-error=172800
> Cache-Control: public
> Cache-Control: max-age=60
> Cache-Control: s-maxage=40
> ETag: "custom-etag"
> Content-Type: text/html;charset=UTF-8
> Transfer-Encoding: chunked
> Date: Fri, 23 Jul 2010 09:00:49 GMT
> Server: CustomServerName
>
> Is this the expected behavior? I've never seen such a response header
> before. Should I issue a bug?
>
>

Re: setHeader vs addHeader problem

Posted by Pid <pi...@pidster.com>.
On 23/07/2010 10:10, Yoryos wrote:
> Hello
> looking at HttpServletResponse
> javadoc<http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpServletResponse.html>
> I
> can understand that the difference between setHeader and addHeader is that
> the first one overrides previous setted one (if any) and the second one just
> ads the new value to an existing one (or create an new one if it doesn't
> exists). I use the second in order to add to my responses Cache-Control
> headers.
> 
> With something like:
> response.addHeader('Cache-Control', 'public');
> response.addHeader('Cache-Control', 'stale-if-error=xxx');
> response.addHeader('Cache-Control', 'max-age=xxx');
> response.addHeader('Cache-Control', 's-maxage=xxx');
> 
> I would expect an one line response header like Cache-Control: public,
> stale-if-error=xxx, max-age=xxx, s-maxage=xxx but what I get is three
> Cache-Control headers:
> 
> *$ telnet localhost 80*
> *HEAD / HTTP/1.1*
> *Host: some.host.com\n\n*
> 
> HTTP/1.1 200 OK
> Cache-Control: stale-if-error=172800
> Cache-Control: public
> Cache-Control: max-age=60
> Cache-Control: s-maxage=40
> ETag: "custom-etag"
> Content-Type: text/html;charset=UTF-8
> Transfer-Encoding: chunked
> Date: Fri, 23 Jul 2010 09:00:49 GMT
> Server: CustomServerName
> 
> Is this the expected behavior? 

Yes.

> I've never seen such a response header
> before. Should I issue a bug?

No.


p