mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8241389: URLConnection::getHeaderFields returns result inconsistent with getHeaderField/Key for FileURLConnection, FtpURLConnection
Reviewed-by: dfuchs
This commit is contained in:
parent
9dc6f10755
commit
2f80d69518
3 changed files with 127 additions and 0 deletions
|
@ -25,6 +25,7 @@
|
|||
|
||||
package sun.net.www;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
|
||||
|
@ -109,6 +110,26 @@ public abstract class URLConnection extends java.net.URLConnection {
|
|||
return properties == null ? null : properties.findValue(name);
|
||||
}
|
||||
|
||||
|
||||
Map<String, List<String>> headerFields;
|
||||
|
||||
@Override
|
||||
public Map<String, List<String>> getHeaderFields() {
|
||||
if (headerFields == null) {
|
||||
try {
|
||||
getInputStream();
|
||||
if (properties == null) {
|
||||
headerFields = super.getHeaderFields();
|
||||
} else {
|
||||
headerFields = properties.getHeaders();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return super.getHeaderFields();
|
||||
}
|
||||
}
|
||||
return headerFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the key for the nth header field. Returns null if
|
||||
* there are fewer than n fields. This can be used to iterate
|
||||
|
|
|
@ -138,6 +138,11 @@ public class FileURLConnection extends URLConnection {
|
|||
}
|
||||
}
|
||||
|
||||
public Map<String,List<String>> getHeaderFields() {
|
||||
initializeHeaders();
|
||||
return super.getHeaderFields();
|
||||
}
|
||||
|
||||
public String getHeaderField(String name) {
|
||||
initializeHeaders();
|
||||
return super.getHeaderField(name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue