8241389: URLConnection::getHeaderFields returns result inconsistent with getHeaderField/Key for FileURLConnection, FtpURLConnection

Reviewed-by: dfuchs
This commit is contained in:
Michael McMahon 2020-05-22 21:59:40 +01:00
parent 9dc6f10755
commit 2f80d69518
3 changed files with 127 additions and 0 deletions

View file

@ -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

View file

@ -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);