hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir H. Pettersen" <g...@cellus.no>
Subject The httpclient.wire log.
Date Wed, 31 Mar 2004 08:57:06 GMT
Hi,

I have been using the commons httpclient successfully since rc1. Great work
guys! This is the best client that I ever have used in java.

The httpclient.wire log is fantastic, but there is something there that
bothers me a bit. Before the characters are written to log, they are decoded
with "US-ASCII" (or the default character set if that fails).

The problem with this is if you try to debug http traces with special
character you will actually lose information on what is actually sent.

My example is: I am having some encoding problems with my client, and I want
to check exactly what bytes I am sending. I am sending the three Norwegian
characters (1)æ (2)ø and (3)å. (ae together, o with a slash and a with a
ring over).

(1)	is encoded in UTF-8 as 0xc3 0xa6
(2)	is encoded in UTF-8 as 0xc3 0xb8
(3)	is encodes in UTF-8 as 0xc3 0xa5

The problem is when I try to POST these three characters. It is logged as:
"[0xfffd][0xfffd][0xfffd][0xfffd][0xfffd][0xfffd]" (but actually that is not
what is sent)

I want the log to be: "[0xc3][0xa6][0xc3][0xb8][0xc3][0xa5]"

A fix for this would be to remove the encoded reader from: Wire.java :
-----------------
…
//      Reader reader = null;
//      try {
//         reader = new InputStreamReader(instream, "US-ASCII");
//      } catch (UnsupportedEncodingException e) {
//         reader = new InputStreamReader(instream);
//      }
      StringBuffer buffer = new StringBuffer();
      int ch;
//      while ((ch = reader.read()) != -1) {
      while ((ch = instream.read()) != -1) {
…
-----------------
Notice that the method now no longer throws an IOException.

Attached is my suggested changes in Wire.java. I did not remove the "throws
IOException" from the method signature, since this may have other
consequences.

Regards,
Geir H. Pettersen
Cellus/Masp Technology AS

Mime
View raw message