You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Hirofumi Arimoto <ar...@geocities.co.jp> on 2000/05/06 08:07:18 UTC
encoding bug
Hi, all.
I found a bug relating to an encoding. I'm now using tomcat v3.1 , which
can't send cookies including japanese characters.
Its root cause is the method
org.apache.tomcat.service.http.HttpResponseAdapter#endHeaders. In this
method, the content of headers is forcely encoded as "8859_1".
So please change to take care of an encoding correctlly when write
headers. I have now seen the CVS repository, but it seems that this bug have
been not fixed yet.
Here is a fix:
----
before:
sout.write( headersSB.toString().getBytes(Constants.CharacterEncoding.Defaul
t) );
----
after:
String encoding = getCharacterEncoding();
if(encoding == null)
out.write( headersSB.toString().getBytes(Constants.CharacterEncoding.Default
) );
else
try {
sout.write( headersSB.toString().getBytes(encoding) );
}catch(java.io.UnsupportedEncodingException ex) {
out.write( headersSB.toString().getBytes(Constants.CharacterEncoding.Default
) );
System.out.println("Unsuported encoding: " + encoding );
}
----
i hope you understand my english :-)
happy hacking!
---
<< Hirofumi Arimoto. Kobe,Japan. >>
Internet Mail : arimot@geocities.co.jp
Yahoo Pager Japan : arimoto
AOL IM Japan : arimot
ICQ : 6795777
---
Re: encoding bug
Posted by Hirofumi Arimoto <ar...@geocities.co.jp>.
Hi Mike,
> Well, note that HTTP/1.1 spec defines most headers using tokens which is
> one or more ascii codes. In fact cookie can only partially contain
> anything but ascii (i.e. in the value). Having everything as 8859-1 is a
> safe way to enforce this. Have you considered if it won't result in bad
> header encodings? I'm really not sure of that - especially if somebody
> choose for example some multibyte encoding for the document.
Okay. I understood the spec.
In fact we usually send multibyte characters as cookie values because both
Netscape and IE can send them and it is no harm as far as I know.
I know there is a solution of this which is to use base64 or somthing but
sometimes this solution have a problem of a servlet compatibility. For
example suppose there is a servlet software which is developed by a person
or a company which don't consider this manner. Then we like japanese may not
use this software because multibyte characters may not be send as cookie
values correctly.
I think that whether multibyte characters are encoded by BASE64 is a
servlet implementer's problem because even though you do permit to use them
as cookie values, it is still a safe way if a servlet implementer considers
it.
Although there is another solution which forcely use a BASE64-like
encoding as in rfc2047, I guess this is not an elegant one.
Please reconsider this problem.
---
<< Hirofumi Arimoto. Kobe,Japan. >>
Internet Mail : arimot@geocities.co.jp
Yahoo Pager Japan : arimoto
AOL IM Japan : arimot
ICQ : 6795777
---
Re: encoding bug
Posted by Michal Mosiewicz <mi...@interdata.com.pl>.
Hirofumi Arimoto wrote:
>
> Hi, all.
> I found a bug relating to an encoding. I'm now using tomcat v3.1 , which
> can't send cookies including japanese characters.
> Its root cause is the method
> org.apache.tomcat.service.http.HttpResponseAdapter#endHeaders. In this
> method, the content of headers is forcely encoded as "8859_1".
Well, note that HTTP/1.1 spec defines most headers using tokens which is
one or more ascii codes. In fact cookie can only partially contain
anything but ascii (i.e. in the value). Having everything as 8859-1 is a
safe way to enforce this. Have you considered if it won't result in bad
header encodings? I'm really not sure of that - especially if somebody
choose for example some multibyte encoding for the document.
-- Mike