You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Christian Hvitved <ch...@gmail.com> on 2007/04/13 18:05:59 UTC

Problem reading the Accept-Encoding header from a request

Hi support list

I am having a problem, with reading the Accept-Encoding header from a
request, which seems very simple.

I use Tomcat  6.0.10 on a dansih windows xp.

The problem arose when I was writing a special compression filter (I don't
want to use the one that ships with tomcat).
When the server recieves a http request containing an Accept-Encoding
header, the header is replaced with a header with the name ---------------
and value ----. The header name and value are just dashes.
I have tested this by creating a filter that prints out all the headers. The
code is shown at the end of the mail. The code prints out all the headers
sent in the request. Except if the Accept-Encoding header is present it is
replaced with dashes.
When I make a request without the Accept-Encoding header I don't see the
header just containing dashes.

I have even tried using another server (Trifork T4) It does the same to the
accept encoding header.

Searching for the answer I found a post on the same problem but without a
solution :(
http://mail-archives.apache.org/mod_mbox/tomcat-users/200407.mbox/%3C1EF8A706A8D5D3418BD785B86B4A847B1002A5@ex-350-02.newcentury.com%3E

Please help me out if you have any ideas why this is happening.

regards
Christian Hvitved


The code in my filter looks like this:

             HttpServletRequest req = (HttpServletRequest)request;

            String headerValue = req.getHeader("Accept-Encoding");
            System.out.println("encoding: " + headerValue);

            Enumeration e = req.getHeaderNames();
            System.out.println("new request............");
            while (e.hasMoreElements()) {
                String header = (String) e.nextElement();
                System.out.println(header);
                System.out.println("Value: " + req.getHeader (header));

            }

Re: Problem reading the Accept-Encoding header from a request

Posted by Rashmi Rubdi <ra...@gmail.com>.
As far as I understand, the Accept-Encoding header is set by the *browser*.

It is also possible to override the browser headers with
HttpResponse's addHeader (if the header doesn't exist) or setHeader
(to overwrite the header)

So you may want to try either one of:

response.addHeader("Accept-Encoding","gzip");

or

response.setHeader("Accept-Encoding","gzip");

Other acceptable encodings are listed in the link I pointed to earlier.

-Rashmi

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problem reading the Accept-Encoding header from a request

Posted by Christian Hvitved <ch...@gmail.com>.
Hi

The firewall on my laptop pc used is norton internet security 2005. It is
running on a danish windows xp. It is possible it has some customized
settings controlled by the administrators.

regards Christian

On 4/14/07, Hassan Schroeder <ha...@gmail.com> wrote:
>
> On 4/14/07, Christian Hvitved <ch...@gmail.com> wrote:
>
> > It was my firewall. It is
>
> > Another thing is, that I think this is a big problem if many firewalls
> make
> > it impossible to compress responses using the accept-encoding header.
>
> Can you clarify what kind of "firewall" you're talking about? Desktop
> software on your Windows PC, dedicated hardware firewall, other?
>
> And in any case, who is the vendor?
>
> --
> Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Problem reading the Accept-Encoding header from a request

Posted by Hassan Schroeder <ha...@gmail.com>.
On 4/14/07, Christian Hvitved <ch...@gmail.com> wrote:

> It was my firewall

> Another thing is, that I think this is a big problem if many firewalls make
> it impossible to compress responses using the accept-encoding header.

Can you clarify what kind of "firewall" you're talking about? Desktop
software on your Windows PC, dedicated hardware firewall, other?

And in any case, who is the vendor?

-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problem reading the Accept-Encoding header from a request

Posted by Christian Hvitved <ch...@gmail.com>.
Hi

And thanks for all the quick help.

It turned out to be a really rookie mistake. It was my firewall, that was
changing my request.

I have to try to defend myself for being so stupid. I am using a coorparate
machine where I cant see the firewall in the tray, so I thought no firewall
was running.

Another thing is, that I think this is a big problem if many firewalls make
it impossible to compress responses using the accept-encoding header.

again thanks to all the people here helping tomcat users.

regards
Christian

On 4/14/07, Martin Gainty <mg...@hotmail.com> wrote:
>
> Good Morning Kristian-
>
> if by weird you mean "you dont understand"  then take a look at
> http://www.xml.com/pub/a/2005/06/22/sparklines.html?page=last
> According to this link a response of dashes is interpreted as "0 bytes
> returned"
>
> A few basic questions:
> Is the server xmitting using HTTP 1.0? In other words are you running
> tomcat
> 3.x?
> If so can you transmit a default value in other words transmit something
> other than 0 bytes?
>
> Transmit via HTTP POST (instead of GET to ensure you are not causing an
> length overrun scenario with HTTP GET)
> Enable HTTPMonitor and trace every response
> What is the Content-Type for this response?
> What is the Content-Length for this reponse?
>
> I found this link quite instructive
> http://www.samspublishing.com/articles/article.asp?p=31443&seqNum=6&rl=1
>
> HTH
> Martin--
> This email message and any files transmitted with it contain confidential
> information intended only for the person(s) to whom this email message is
> addressed.  If you have received this email message in error, please
> notify
> the sender immediately by telephone or email and destroy the original
> message without making a copy.  Thank you.
>
> ----- Original Message -----
> From: "Christian Hvitved" <ch...@gmail.com>
> To: "Tomcat Users List" <us...@tomcat.apache.org>
> Sent: Saturday, April 14, 2007 3:13 AM
> Subject: Re: Problem reading the Accept-Encoding header from a request
>
>
> > Thank you very much for the comments.
> >
> > But I'm still not sure why I have problems reading the Accept-Encoding
> > header on the server.
> >
> > My problem is when I recieve the request on the server (And I know by
> > using
> > a proxy that the request contains an Accept-Encoding header). At the
> > server
> > I cannot read the accept-encoding header, instead I get a header
> > consisting
> > of dashes.
> >
> > It doesn't matter if I try to read the headers of the request in a
> filter
> > or
> > servlet/jsp - I have the same problem.
> >
> > When I generate the html response to the client I use this in the head
> tag
> > of the html page:
> > <meta content="text/html; charset=UTF-8" http-equiv="content-type" />
> > But I cannot see why this should have anything to do with reading
> headers
> > from the request.
> >
> > I'm really stuck in this weird problem
> >
> > regards, and thanks again.
> > Christian
> >
> >
> > On 4/13/07, Rashmi Rubdi <ra...@gmail.com> wrote:
> >>
> >> > The problem arose when I was writing a special compression filter
> >>
> >> I tried your code in a JSP directly (without using any other custom
> >> compression filter)
> >> and it prints as follows:
> >>
> >> Accept-Encoding gzip,deflate
> >>
> >> some other headers......
> >>
> >>
> >> accept
> >> text/xml,application/xml,application/xhtml+xml,text/html;q=
> >> 0.9,text/plain;q=0.8 ,image/png,*/*;q=0.5
> >>
> >> accept-language         en-us,en;q=0.5
> >>
> >> accept-encoding         gzip,deflate
> >>
> >> accept-charset  UTF-8,*
> >>
> >> some more headers..........
> >>
> >> The description of Accept-Encoding may give you additional clues as to
> >> why you're getting dashes instead (when you use a custom compression):
> >> http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
> >>
> >>
> >> -Rashmi
> >>
> >> On 4/13/07, Christian Hvitved <ch...@gmail.com> wrote:
> >>
> >> > The code in my filter looks like this:
> >> >
> >> >              HttpServletRequest req = (HttpServletRequest)request;
> >> >
> >> >             String headerValue = req.getHeader("Accept-Encoding");
> >> >             System.out.println("encoding: " + headerValue);
> >> >
> >> >             Enumeration e = req.getHeaderNames ();
> >> >             System.out.println("new request............");
> >> >             while (e.hasMoreElements()) {
> >> >                 String header = (String) e.nextElement();
> >> >                 System.out.println(header);
> >> >                 System.out.println("Value: " + req.getHeader(header));
> >> >
> >> >             }
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To start a new topic, e-mail: users@tomcat.apache.org
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Problem reading the Accept-Encoding header from a request

Posted by Martin Gainty <mg...@hotmail.com>.
Good Morning Kristian-

if by weird you mean "you dont understand"  then take a look at
http://www.xml.com/pub/a/2005/06/22/sparklines.html?page=last
According to this link a response of dashes is interpreted as "0 bytes 
returned"

A few basic questions:
Is the server xmitting using HTTP 1.0? In other words are you running tomcat 
3.x?
If so can you transmit a default value in other words transmit something 
other than 0 bytes?

Transmit via HTTP POST (instead of GET to ensure you are not causing an 
length overrun scenario with HTTP GET)
Enable HTTPMonitor and trace every response
What is the Content-Type for this response?
What is the Content-Length for this reponse?

I found this link quite instructive
http://www.samspublishing.com/articles/article.asp?p=31443&seqNum=6&rl=1

HTH
Martin--
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed.  If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy.  Thank you.

----- Original Message ----- 
From: "Christian Hvitved" <ch...@gmail.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Saturday, April 14, 2007 3:13 AM
Subject: Re: Problem reading the Accept-Encoding header from a request


> Thank you very much for the comments.
>
> But I'm still not sure why I have problems reading the Accept-Encoding
> header on the server.
>
> My problem is when I recieve the request on the server (And I know by 
> using
> a proxy that the request contains an Accept-Encoding header). At the 
> server
> I cannot read the accept-encoding header, instead I get a header 
> consisting
> of dashes.
>
> It doesn't matter if I try to read the headers of the request in a filter 
> or
> servlet/jsp - I have the same problem.
>
> When I generate the html response to the client I use this in the head tag
> of the html page:
> <meta content="text/html; charset=UTF-8" http-equiv="content-type" />
> But I cannot see why this should have anything to do with reading headers
> from the request.
>
> I'm really stuck in this weird problem
>
> regards, and thanks again.
> Christian
>
>
> On 4/13/07, Rashmi Rubdi <ra...@gmail.com> wrote:
>>
>> > The problem arose when I was writing a special compression filter
>>
>> I tried your code in a JSP directly (without using any other custom
>> compression filter)
>> and it prints as follows:
>>
>> Accept-Encoding gzip,deflate
>>
>> some other headers......
>>
>>
>> accept 
>> text/xml,application/xml,application/xhtml+xml,text/html;q=
>> 0.9,text/plain;q=0.8 ,image/png,*/*;q=0.5
>>
>> accept-language         en-us,en;q=0.5
>>
>> accept-encoding         gzip,deflate
>>
>> accept-charset  UTF-8,*
>>
>> some more headers..........
>>
>> The description of Accept-Encoding may give you additional clues as to
>> why you're getting dashes instead (when you use a custom compression):
>> http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
>>
>>
>> -Rashmi
>>
>> On 4/13/07, Christian Hvitved <ch...@gmail.com> wrote:
>>
>> > The code in my filter looks like this:
>> >
>> >              HttpServletRequest req = (HttpServletRequest)request;
>> >
>> >             String headerValue = req.getHeader("Accept-Encoding");
>> >             System.out.println("encoding: " + headerValue);
>> >
>> >             Enumeration e = req.getHeaderNames ();
>> >             System.out.println("new request............");
>> >             while (e.hasMoreElements()) {
>> >                 String header = (String) e.nextElement();
>> >                 System.out.println(header);
>> >                 System.out.println("Value: " + req.getHeader (header));
>> >
>> >             }
>> >
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
> 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problem reading the Accept-Encoding header from a request

Posted by Christian Hvitved <ch...@gmail.com>.
Thank you very much for the comments.

But I'm still not sure why I have problems reading the Accept-Encoding
header on the server.

My problem is when I recieve the request on the server (And I know by using
a proxy that the request contains an Accept-Encoding header). At the server
I cannot read the accept-encoding header, instead I get a header consisting
of dashes.

It doesn't matter if I try to read the headers of the request in a filter or
servlet/jsp - I have the same problem.

When I generate the html response to the client I use this in the head tag
of the html page:
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
But I cannot see why this should have anything to do with reading headers
from the request.

I'm really stuck in this weird problem

regards, and thanks again.
Christian


On 4/13/07, Rashmi Rubdi <ra...@gmail.com> wrote:
>
> > The problem arose when I was writing a special compression filter
>
> I tried your code in a JSP directly (without using any other custom
> compression filter)
> and it prints as follows:
>
> Accept-Encoding gzip,deflate
>
> some other headers......
>
>
> accept          text/xml,application/xml,application/xhtml+xml,text/html;q=
> 0.9,text/plain;q=0.8 ,image/png,*/*;q=0.5
>
> accept-language         en-us,en;q=0.5
>
> accept-encoding         gzip,deflate
>
> accept-charset  UTF-8,*
>
> some more headers..........
>
> The description of Accept-Encoding may give you additional clues as to
> why you're getting dashes instead (when you use a custom compression):
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
>
>
> -Rashmi
>
> On 4/13/07, Christian Hvitved <ch...@gmail.com> wrote:
>
> > The code in my filter looks like this:
> >
> >              HttpServletRequest req = (HttpServletRequest)request;
> >
> >             String headerValue = req.getHeader("Accept-Encoding");
> >             System.out.println("encoding: " + headerValue);
> >
> >             Enumeration e = req.getHeaderNames ();
> >             System.out.println("new request............");
> >             while (e.hasMoreElements()) {
> >                 String header = (String) e.nextElement();
> >                 System.out.println(header);
> >                 System.out.println("Value: " + req.getHeader (header));
> >
> >             }
> >
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: Problem reading the Accept-Encoding header from a request

Posted by Rashmi Rubdi <ra...@gmail.com>.
> The problem arose when I was writing a special compression filter

I tried your code in a JSP directly (without using any other custom
compression filter)
and it prints as follows:

Accept-Encoding gzip,deflate

some other headers......

accept  	text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

accept-language 	en-us,en;q=0.5

accept-encoding 	gzip,deflate

accept-charset 	UTF-8,*

some more headers..........

The description of Accept-Encoding may give you additional clues as to
why you're getting dashes instead (when you use a custom compression):
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html


-Rashmi

On 4/13/07, Christian Hvitved <ch...@gmail.com> wrote:

> The code in my filter looks like this:
>
>              HttpServletRequest req = (HttpServletRequest)request;
>
>             String headerValue = req.getHeader("Accept-Encoding");
>             System.out.println("encoding: " + headerValue);
>
>             Enumeration e = req.getHeaderNames();
>             System.out.println("new request............");
>             while (e.hasMoreElements()) {
>                 String header = (String) e.nextElement();
>                 System.out.println(header);
>                 System.out.println("Value: " + req.getHeader (header));
>
>             }
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problem reading the Accept-Encoding header from a request

Posted by Martin Gainty <mg...@hotmail.com>.
Read this excellent tutorial
http://www.sitepoint.com/blogs/2006/03/15/do-you-know-your-character-encodings/
To change the encoding one must change the charset meta tag as in
<META  charset= from ASCII (7bit) or ISO-8859 (8bit) to UCS based encodings
UTF-8 (8 bit represenation of UCS)
UTF-16 (16 bit representation of UCS)
UTF-32 (32 bit representation of UCS)

Tak/
Martin

This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed.  If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy.  Thank you.

----- Original Message ----- 
From: "Christian Hvitved" <ch...@gmail.com>
To: <us...@tomcat.apache.org>
Sent: Friday, April 13, 2007 12:05 PM
Subject: Problem reading the Accept-Encoding header from a request


> Hi support list
>
> I am having a problem, with reading the Accept-Encoding header from a
> request, which seems very simple.
>
> I use Tomcat  6.0.10 on a dansih windows xp.
>
> The problem arose when I was writing a special compression filter (I don't
> want to use the one that ships with tomcat).
> When the server recieves a http request containing an Accept-Encoding
> header, the header is replaced with a header with the name ---------------
> and value ----. The header name and value are just dashes.
> I have tested this by creating a filter that prints out all the headers. 
> The
> code is shown at the end of the mail. The code prints out all the headers
> sent in the request. Except if the Accept-Encoding header is present it is
> replaced with dashes.
> When I make a request without the Accept-Encoding header I don't see the
> header just containing dashes.
>
> I have even tried using another server (Trifork T4) It does the same to 
> the
> accept encoding header.
>
> Searching for the answer I found a post on the same problem but without a
> solution :(
> http://mail-archives.apache.org/mod_mbox/tomcat-users/200407.mbox/%3C1EF8A706A8D5D3418BD785B86B4A847B1002A5@ex-350-02.newcentury.com%3E
>
> Please help me out if you have any ideas why this is happening.
>
> regards
> Christian Hvitved
>
>
> The code in my filter looks like this:
>
>             HttpServletRequest req = (HttpServletRequest)request;
>
>            String headerValue = req.getHeader("Accept-Encoding");
>            System.out.println("encoding: " + headerValue);
>
>            Enumeration e = req.getHeaderNames();
>            System.out.println("new request............");
>            while (e.hasMoreElements()) {
>                String header = (String) e.nextElement();
>                System.out.println(header);
>                System.out.println("Value: " + req.getHeader (header));
>
>            }
> 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org