Kaffe's HttpURLConnection implementation is broken

Nic Ferrier kaffe@rufus.w3.org
Thu, 08 Jun 2000 02:06:40 +0100


This is a MIME message. If you are reading this text, you may want to 
consider changing to a mail reader or gateway that understands how to 
properly handle MIME multipart messages.

--=_61396BFF.A5C4A82A
Content-Type: text/plain; charset=US-ASCII
Content-Disposition: inline

The current HttpURLConnection does not handle headers properly... or
anything like Sun's implementation.

The Kaffe impl uses a fixed array of response header keys which
indexes an instance array of values for those keys.


This has 2 problems:

1. if a particular key (that is present in the index) is not present
in the response the associated value will be null... this causes 2
problems:
(i) if a key is returned by:
   HttpURLConnection.getHeaderFieldKey(int)
then it's associated value should NEVER be null - with the current
Kaffe implementation it will be.

2. if additional response headers are sent by the server Kaffe will
never detect them.
This is a BIG problem. I have been helping someone on the Sun
Servlet-Interest list who was developing a proxy server using
HttpURLConnection, using Kaffe a proxy server would be impossible this
way.
So would an applet based tool which wanted to persist cookies over
connections.


There is also a third incompatability with the Sun version:

3. with Sun the header index 0 is reserved for the response message
so the header doesn't start till index: 1


I have redeveloped the class, my version is attached. 


How does the new implementation work?
It uses 2 Vector classes, 1 for keys and 1 for values. It needs to be
done like this (rather than with a hash) because of the appaling way
the class is speced.

The header manipulation uses int indexed methods which can only
return String, int or long.


Why can't a simple hash be used?
Therefore a hash cannot be used because if it were headers with
multiple values (such as Cookie) could only ever return the first
value.

The indexed system gets around this but requires the int indexing and
therefore the Vectors.


Have we lost performance?
There is still a quick index system of well known fields but this is
not really necessary and Kaffe maintainers might want to get rid of
it.

The implementation also changes the way the header is parsed to make
it more robust and ensures that the response line is stored at header
line index 0.



Could someone put this into Kaffe please? or fix the problem?


A couple of other (related) things:

- the BasicURLConnection needs to be altered too... I'm happy to do
that if people want me to (please let me know)

- I'm working on an HTTP/1.1 version which allows re-use of
connections by caching persistent connections for a short period of
time... it will use a single thread to manage the system.
Is there any interest in this?
Would people prefer it as an additional option rather than a
replacement of the current version?

- I'd never realised how utterly appaling this class was - is there
anyway Kaffe can lobby Sun to change this class? 
The header manipulation is absolutely awfull - a response header
needs to be treated as a hash of Strings or String[]s. See the Servlet
API for details.



Nic Ferrier

--=_61396BFF.A5C4A82A
Content-Type: application/octet-stream; name="HttpURLConnection.java"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="HttpURLConnection.java"

LyoNCiAqIEh0dHBVUkxDb25uZWN0aW9uIC0NCiAqICBTaW1wbGUgSFRUUCBVUkwgaGFuZGxlci4N
CiAqDQogKiBDb3B5cmlnaHQgKGMpIDE5OTgsIDE5OTkNCiAqICAgICAgVHJhbnN2aXJ0dWFsIFRl
Y2hub2xvZ2llcywgSW5jLiAgQWxsIHJpZ2h0cyByZXNlcnZlZC4NCiAqDQogKiBTZWUgdGhlIGZp
bGUgImxpY2Vuc2UudGVybXMiIGZvciBpbmZvcm1hdGlvbiBvbiB1c2FnZSBhbmQgcmVkaXN0cmli
dXRpb24NCiAqIG9mIHRoaXMgZmlsZS4NCiAqLw0KDQpwYWNrYWdlIGthZmZlLm5ldC53d3cucHJv
dG9jb2wuaHR0cDsNCg0KaW1wb3J0IGphdmEuaW8uSU9FeGNlcHRpb247DQppbXBvcnQgamF2YS5p
by5JbnB1dFN0cmVhbTsNCmltcG9ydCBqYXZhLmlvLk91dHB1dFN0cmVhbTsNCmltcG9ydCBqYXZh
LmlvLkRhdGFPdXRwdXRTdHJlYW07DQppbXBvcnQgamF2YS5pby5EYXRhSW5wdXRTdHJlYW07DQpp
bXBvcnQgamF2YS5pby5CdWZmZXJlZElucHV0U3RyZWFtOw0KLy9pbXBvcnQgamF2YS51dGlsLlN0
cmluZ1Rva2VuaXplcjsgLy90aGlzIHRha2VuIG91dCBhbmQgcmVwbGFjZWQgd2l0aCBpbmRpdmlk
dWFsIHBhcnNpbmcNCmltcG9ydCBqYXZhLnV0aWwuVmVjdG9yOw0KaW1wb3J0IGphdmEubmV0LlVS
TDsNCmltcG9ydCBqYXZhLm5ldC5VUkxDb25uZWN0aW9uOw0KaW1wb3J0IGphdmEubm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