Bug 24104 - HttpUrlConnection header map includes the protocol and status
Summary: HttpUrlConnection header map includes the protocol and status
Status: RESOLVED FIXED
Alias: None
Product: classpath
Classification: Unclassified
Component: classpath (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: 0.19
Assignee: David Daney
URL:
Keywords: patch
Depends on:
Blocks: 16229
  Show dependency treegraph
 
Reported: 2005-09-28 14:59 UTC by Phil Shaw
Modified: 2005-10-23 23:08 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-10-03 15:35:17


Attachments
A simple test case for the bug. (778 bytes, text/plain)
2005-09-28 15:01 UTC, Phil Shaw
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Phil Shaw 2005-09-28 14:59:05 UTC
The map returned by getHeaderFields includes a header key which is the empty
string mapped to the value 'HTTP/1.1 200 OK', for example.
Comment 1 Phil Shaw 2005-09-28 15:01:30 UTC
Created attachment 9826 [details]
A simple test case for the bug.

A test program that checks for the empty string key and lists all headers.
Compile and run main without any arguments.
Comment 2 Tom Tromey 2005-09-29 17:07:52 UTC
When I try this with the IBM JDK, I see a 'null' key.
I had to slightly modify the test case so it didn't throw
an NPE in this case.

output snippet:

Test failed, header keys contain the empty string.
Header: null
Value: HTTP/1.1 200 OK
Comment 3 David Daney 2005-10-03 15:35:17 UTC
The real bug is that the key for the status line is the empty string instead of null.  It is not documented anywhere that I know of, but Sun's runtime returns a set containing the status line and according to the comment that tromey posted, so  does IBM's.  The existance of the status line is not a bug.  The problem is the key.
Comment 4 David Daney 2005-10-04 16:18:06 UTC
Proposed patch here:

http://lists.gnu.org/archive/html/classpath-patches/2005-10/msg00054.html
Comment 5 cvs-commit@developer.classpath.org 2005-10-12 20:26:27 UTC
Subject: Bug 24104

CVSROOT:	/cvsroot/classpath
Module name:	classpath
Branch: 	
Changes by:	David Daney <daney@savannah.gnu.org>	05/10/12 19:48:25

Modified files:
	.              : ChangeLog 
	gnu/java/net/protocol/http: ChunkedInputStream.java Cookie.java 
	                            HTTPConnection.java 
	                            HTTPURLConnection.java Headers.java 
	                            Request.java Response.java 
Added files:
	gnu/java/net/protocol/http: LimitedLengthInputStream.java 
Removed files:
	gnu/java/net/protocol/http: ByteArrayResponseBodyReader.java 
	                            ResponseBodyReader.java 
	gnu/java/net/protocol/http/event: ConnectionEvent.java 
	                                  ConnectionListener.java 
	                                  RequestEvent.java 
	                                  RequestListener.java 
	                                  package.html 

Log message:
	2005-10-12  David Daney  <ddaney@avtrex.com>
	
	PR classpath/24086, PR classpath/24091, PR classpath/24104
	* gnu/java/net/protocol/http/ByteArrayResponseBodyReader.java: Removed.
	* gnu/java/net/protocol/http/ResponseBodyReader.java: Removed.
	* gnu/java/net/protocol/http/event/ConnectionEvent.java: Removed.
	* gnu/java/net/protocol/http/event/ConnectionListener.java: Removed.
	* gnu/java/net/protocol/http/event/RequestEvent.java: Removed.
	* gnu/java/net/protocol/http/event/RequestListener.java: Removed.
	* gnu/java/net/protocol/http/event/package.html: Removed.
	* gnu/java/net/protocol/http/HTTPConnection.java: Cleaned up imports.
	(connectionListeners): Removed.
	(requestListeners): Removed.
	(pool): New field.
	(Constructor): Don't initialize connectionListeners or
	requestListeners.
	(useCount): New field.
	(getPoolKey): New method.
	(setPool): New method.
	(release): New method.
	(newRequest): Don't call fireRequestEvent. Use StringBuilder instead
	of StringBuffer.
	(close): Don't call fireConnectionEvent.
	(getURI):Use StringBuilder instead of StringBuffer.
	(addConnectionListener): Removed.
	(removeConnectionListener): Removed.
	(fireConnectionEvent): Removed.
	(addRequestListener): Removed.
	(removeRequestListener): Removed.
	(fireRequestEvent): Removed.
	* gnu/java/net/protocol/http/HTTPURLConnection.java:Cleaned up imports.
	(connectionPool): Changed type to LinkedHashMap.
	(maxConnections): Made static.
	(responseSink): Changed type to InputStream.
	(errorSink): Likewise.
	(connect): Eliminate reader.  Get responseSink from response.
	(getConnection): Rewrote.
	(getHeaderFields): Use null as key for status line.  Return
	unmodifiable Map.
	* gnu/java/net/protocol/http/Headers.java: Extend LinkedHashMap,
	instead of implement Map.
	(headers): Removed.
	(Constructor): Do not initialize headers.
	(size): Removed.
	(isEmpth): Removed.
	(containsKey): Rewrote.
	(containsValue): Removed.
	(get): Call super.get().
	(getValue): Likewise.
	(getLongValue): New method.
	(put): Call super.put().
	(remove): Call super.remove().
	(putAll): Rewrote.
	(clear): Removed.
	(keySet): Call super.keySet().
	(values): Removed.
	(entrySet): Call super.entrySet().
	(equals): Removed.
	(hashCode): Removed.
	(parse): Use StringBuilder instead of StringBuffer.
	(addValue): Call super.* instead of headers.*.
	* gnu/java/net/protocol/http/LimitedLengthInputStream.java: New class.
	* gnu/java/net/protocol/http/Request.java: Cleaned up imports.
	(responseBodyReader): Removed.
	(setResponseBodyReader): Removed.
	(dispatch): Don't create LineInputStream.  Don't call fireRequestEvent.
	Don't append CRLF to Request body.  Handle unsolicited 100 Continue
	response.
	(readResponse): Rewrote.
	(readResponseBody): Renamed to ...
	(createResponseBodyStream): ... And rewritten.
	(parseAuthParams): Use StringBuilder instead of StringBuffer.
	(getNonceCount): Likewise.
	(handleSetCookie): Likewise.
	* gnu/java/net/protocol/http/Response.java: Cleaned up imports.
	(codeClass): Removed.
	(body): New field.
	(Constructor): Don't initialize codeClass.  Initialize body.
	(getCodeClass): Rewrote.
	(getLongHeader): New method.
	(getBody): New method.
	* gnu/java/net/protocol/http/ChunkedInputStream.java (read): Use
	StringBuilder instead of StringBuffer.
	* gnu/java/net/protocol/http/Cookie.java (toString): Use StringBuilder
	instead of StringBuffer.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/classpath/classpath/ChangeLog.diff?tr1=1.5202&tr2=1.5203&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/classpath/classpath/gnu/java/net/protocol/http/LimitedLengthInputStream.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/classpath/classpath/gnu/java/net/protocol/http/ChunkedInputStream.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/classpath/classpath/gnu/java/net/protocol/http/Cookie.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/classpath/classpath/gnu/java/net/protocol/http/HTTPConnection.java.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/classpath/classpath/gnu/java/net/protocol/http/HTTPURLConnection.java.diff?tr1=1.14&tr2=1.15&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/classpath/classpath/gnu/java/net/protocol/http/Headers.java.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/classpath/classpath/gnu/java/net/protocol/http/Request.java.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/classpath/classpath/gnu/java/net/protocol/http/Response.java.diff?tr1=1.2&tr2=1.3&r1=text&r2=text




Comment 6 David Daney 2005-10-12 20:30:52 UTC
Fixed by the patch.
Comment 7 David Daney 2005-10-20 17:56:50 UTC
Subject: Bug 24104

Author: daney
Date: Thu Oct 20 17:56:44 2005
New Revision: 105372

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=105372
Log:
2005-10-12  David Daney  <ddaney@avtrex.com>

	PR classpath/24086, PR classpath/24091, PR classpath/24104 (test commit to test svn repository)
	* gnu/java/net/protocol/http/ByteArrayResponseBodyReader.java: Removed.
	* gnu/java/net/protocol/http/ResponseBodyReader.java: Removed.
	* gnu/java/net/protocol/http/event/ConnectionEvent.java: Removed.
	* gnu/java/net/protocol/http/event/ConnectionListener.java: Removed.
	* gnu/java/net/protocol/http/event/RequestEvent.java: Removed.
	* gnu/java/net/protocol/http/event/RequestListener.java: Removed.
	* gnu/java/net/protocol/http/event/package.html: Removed.
	* gnu/java/net/protocol/http/HTTPConnection.java: Cleaned up imports.
	(connectionListeners): Removed.
	(requestListeners): Removed.
	(pool): New field.
	(Constructor): Don't initialize connectionListeners or
	requestListeners.
	(useCount): New field.
	(getPoolKey): New method.
	(setPool): New method.
	(release): New method.
	(newRequest): Don't call fireRequestEvent. Use StringBuilder instead
	of StringBuffer.
	(close): Don't call fireConnectionEvent.
	(getURI):Use StringBuilder instead of StringBuffer.
	(addConnectionListener): Removed.
	(removeConnectionListener): Removed.
	(fireConnectionEvent): Removed.
	(addRequestListener): Removed.
	(removeRequestListener): Removed.
	(fireRequestEvent): Removed.
	* gnu/java/net/protocol/http/HTTPURLConnection.java:Cleaned up imports.
	(connectionPool): Changed type to LinkedHashMap.
	(maxConnections): Made static.
	(responseSink): Changed type to InputStream.
	(errorSink): Likewise.
	(connect): Eliminate reader.  Get responseSink from response.
	(getConnection): Rewrote.
	(getHeaderFields): Use null as key for status line.  Return
	unmodifiable Map.
	* gnu/java/net/protocol/http/Headers.java: Extend LinkedHashMap,
	instead of implement Map.
	(headers): Removed.
	(Constructor): Do not initialize headers.
	(size): Removed.
	(isEmpth): Removed.
	(containsKey): Rewrote.
	(containsValue): Removed.
	(get): Call super.get().
	(getValue): Likewise.
	(getLongValue): New method.
	(put): Call super.put().
	(remove): Call super.remove().
	(putAll): Rewrote.
	(clear): Removed.
	(keySet): Call super.keySet().
	(values): Removed.
	(entrySet): Call super.entrySet().
	(equals): Removed.
	(hashCode): Removed.
	(parse): Use StringBuilder instead of StringBuffer.
	(addValue): Call super.* instead of headers.*.
	* gnu/java/net/protocol/http/LimitedLengthInputStream.java: New class.
	* gnu/java/net/protocol/http/Request.java: Cleaned up imports.
	(responseBodyReader): Removed.
	(setResponseBodyReader): Removed.
	(dispatch): Don't create LineInputStream.  Don't call fireRequestEvent.
	Don't append CRLF to Request body.  Handle unsolicited 100 Continue
	response.
	(readResponse): Rewrote.
	(readResponseBody): Renamed to ...
	(createResponseBodyStream): ... And rewritten.
	(parseAuthParams): Use StringBuilder instead of StringBuffer.
	(getNonceCount): Likewise.
	(handleSetCookie): Likewise.
	* gnu/java/net/protocol/http/Response.java: Cleaned up imports.
	(codeClass): Removed.
	(body): New field.
	(Constructor): Don't initialize codeClass.  Initialize body.
	(getCodeClass): Rewrote.
	(getLongHeader): New method.
	(getBody): New method.
	* gnu/java/net/protocol/http/ChunkedInputStream.java (read): Use
	StringBuilder instead of StringBuffer.
	* gnu/java/net/protocol/http/Cookie.java (toString): Use StringBuilder
	instead of StringBuffer.

Removed:
    trunk/libjava/classpath/gnu/java/net/protocol/http/ByteArrayResponseBodyReader.java
    trunk/libjava/classpath/gnu/java/net/protocol/http/ResponseBodyReader.java
    trunk/libjava/classpath/gnu/java/net/protocol/http/event/
Modified:
    trunk/libjava/classpath/ChangeLog
    trunk/libjava/classpath/gnu/java/net/protocol/http/ChunkedInputStream.java
    trunk/libjava/classpath/gnu/java/net/protocol/http/Cookie.java
    trunk/libjava/classpath/gnu/java/net/protocol/http/HTTPConnection.java
    trunk/libjava/classpath/gnu/java/net/protocol/http/HTTPURLConnection.java
    trunk/libjava/classpath/gnu/java/net/protocol/http/Headers.java
    trunk/libjava/classpath/gnu/java/net/protocol/http/Request.java
    trunk/libjava/classpath/gnu/java/net/protocol/http/Response.java