|
9 | 9 | import java.net.HttpURLConnection; |
10 | 10 | import java.net.URL; |
11 | 11 | import java.net.URLConnection; |
| 12 | +import java.util.ArrayList; |
| 13 | +import java.util.HashMap; |
12 | 14 | import java.util.Hashtable; |
13 | 15 | import java.util.List; |
14 | 16 | import java.util.Map; |
@@ -59,9 +61,50 @@ protected AjaxURLConnection(URL url) { |
59 | 61 |
|
60 | 62 | @Override |
61 | 63 | public String getHeaderField(String name) { |
62 | | - return /** @j2sNative this.info && this.info.xhr && this.info.xhr.getResponseHeader(name) || */null; |
| 64 | + try { |
| 65 | + if (getResponseCode() != -1) { |
| 66 | + return /** |
| 67 | + * @j2sNative this.info && this.info.xhr && |
| 68 | + * this.info.xhr.getResponseHeader(name) || |
| 69 | + */ |
| 70 | + null; |
| 71 | + } |
| 72 | + } catch (IOException e) { |
| 73 | + } |
| 74 | + return null; |
63 | 75 | } |
64 | 76 |
|
| 77 | + |
| 78 | + @SuppressWarnings("unused") |
| 79 | + @Override |
| 80 | + public Map<String, List<String>> getHeaderFields() { |
| 81 | + Map<String, List<String>> map = new HashMap<>(); |
| 82 | + try { |
| 83 | + if (getResponseCode() != -1) { |
| 84 | + String[] data = null; |
| 85 | + /** |
| 86 | + * @j2sNative data = this.info && this.info.xhr && |
| 87 | + * this.info.xhr.getAllResponseHeaders(); data && (data = |
| 88 | + * data.trim().split("\n")); |
| 89 | + */ |
| 90 | + // ["content-length: 996" |
| 91 | + // , "content-type: text/plain; charset=x-user-defined" |
| 92 | + // , "last-modified: Fri, 01 May 2020 11:54:13 GMT"] |
| 93 | + if (data != null) { |
| 94 | + for (int i = 0; i < data.length; i++) { |
| 95 | + String[] parts = data[i].split(":"); |
| 96 | + String key = parts[0].trim(); |
| 97 | + List<String> list = map.get(key); |
| 98 | + if (list == null) |
| 99 | + map.put(key, list = new ArrayList<>()); |
| 100 | + list.add(parts[1].trim()); |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | + } catch (IOException e) { |
| 105 | + } |
| 106 | + return map; |
| 107 | + } |
65 | 108 |
|
66 | 109 | /** |
67 | 110 | * |
@@ -421,7 +464,7 @@ public Object getContents() { |
421 | 464 | return doAjax(false, null); |
422 | 465 | } |
423 | 466 |
|
424 | | - @Override |
| 467 | + @Override |
425 | 468 | public int getResponseCode() throws IOException { |
426 | 469 | /* |
427 | 470 | * Check to see if have the response code already |
|
0 commit comments