-
Notifications
You must be signed in to change notification settings - Fork 5
/
ReadHttpHeaders.js
44 lines (38 loc) · 1.4 KB
/
ReadHttpHeaders.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
var readHttpHeaders = function (doc) {
if (doc !== null && doc.getId() !== null) {
var HttpURLConnection = java.net.HttpURLConnection;
var URL = java.net.URL;
var Iterator = java.util.Iterator;
var String = java.lang.String;
var e = java.lang.Exception;
try {
var url = new URL(doc.getId());
var conn = java.net.HttpURLConnection;
conn = url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
var status = conn.getResponseCode();
var iter = conn.getHeaderFields().keySet().iterator();
if (status == HttpURLConnection.HTTP_OK ||
status == HttpURLConnection.HTTP_MOVED_PERM) {
var key, header = "";
while (iter.hasNext()) {
key = iter.next();
header = conn.getHeaderField(key);
logger.info("Key: " + key + " header value: " + header);
doc.addField(key, header);
}
} else {
logger.info("Staus: " + status);
}
} catch (e) {
logger.error(e);
}
}
return doc;
}