Added getCookies func (#184)

This commit is contained in:
cyian-1756 2017-11-13 05:17:21 -05:00 committed by metaprime
parent e12d4a3d15
commit c1de0ff8e5

View File

@ -522,4 +522,26 @@ public class Utils {
return null;
}
private static HashMap<String, HashMap<String, String>> cookieCache;
static {
cookieCache = new HashMap<String, HashMap<String, String>>();
}
public static Map<String, String> getCookies(String host) {
HashMap<String, String> domainCookies = cookieCache.get(host);
if (domainCookies == null) {
domainCookies = new HashMap<String, String>();
String cookiesConfig = getConfigString("cookies." + host, "");
for (String pair : cookiesConfig.split(" ")) {
pair = pair.trim();
if (pair.contains("=")) {
String[] pieces = pair.split("=", 2);
domainCookies.put(pieces[0], pieces[1]);
}
}
cookieCache.put(host, domainCookies);
}
return domainCookies;
}
}