-
Bug
-
Resolution: Fixed
-
P2
-
None
-
b25
The following happens with HttpURLConnection
Consider the following code with the specs quoted
URLConnection urlConnection = new URL("http://oracle.com").openConnection();
// "It returns null if there are fewer than n+1 fields.
// This method can be used in conjunction with the getHeaderFieldKey method
// to iterate through all the headers in the message."
System.out.println(urlConnection.getHeaderField(0));
// Returns the key for the nth header field.
// It returns null if there are fewer than n+1 fields.
System.out.println(urlConnection.getHeaderFieldKey(0));
Map<String, List<String>> headerFields = urlConnection.getHeaderFields();
System.out.println("headerFields = " + headerFields);
The output would be:
HTTP/1.0 301 Moved Permanently
null
headerFields = {null=[HTTP/1.0 301 Moved Permanently], Connection=[close], Content-Length=[0], Location=[https://www.oracle.com/]}
getHeaderField(int) could not be used in conjunction with getHeaderFieldKey(int) and behavior of the latter doesn't conform to its specification
Consider the following code with the specs quoted
URLConnection urlConnection = new URL("http://oracle.com").openConnection();
// "It returns null if there are fewer than n+1 fields.
// This method can be used in conjunction with the getHeaderFieldKey method
// to iterate through all the headers in the message."
System.out.println(urlConnection.getHeaderField(0));
// Returns the key for the nth header field.
// It returns null if there are fewer than n+1 fields.
System.out.println(urlConnection.getHeaderFieldKey(0));
Map<String, List<String>> headerFields = urlConnection.getHeaderFields();
System.out.println("headerFields = " + headerFields);
The output would be:
HTTP/1.0 301 Moved Permanently
null
headerFields = {null=[HTTP/1.0 301 Moved Permanently], Connection=[close], Content-Length=[0], Location=[https://www.oracle.com/]}
getHeaderField(int) could not be used in conjunction with getHeaderFieldKey(int) and behavior of the latter doesn't conform to its specification
- csr for
-
JDK-8245582 j.net.URLConnection::getHeaderFieldKey(int) behavior does not reliably conform to its specification
- Closed
- is cloned by
-
JDK-8241389 URLConnection::getHeaderFields returns result inconsistent with getHeaderField/Key for FileURLConnection, FtpURLConnection
- Closed