Created
May 12, 2014 15:07
-
-
Save jodaka/f4d5998e6faaf97075ca to your computer and use it in GitHub Desktop.
Webkit cookies proxy for android-async-http
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* We need dummy cookie storage that wouldn't save any cookies | |
* or get any cookies | |
*/ | |
public class WebkitCookietHandlerProxy extends CookieHandler { | |
@Override | |
public void put(URI uri, Map<String, List<String>> responseHeaders) throws IOException { | |
if (uri == null || responseHeaders == null) { | |
return; | |
} | |
String url = uri.toString(); | |
for (String headerKey : responseHeaders.keySet()) { | |
if (headerKey == null || !(headerKey.equalsIgnoreCase("Set-Cookie2") || headerKey.equalsIgnoreCase("Set-Cookie"))) { | |
continue; | |
} | |
for (String headerValue : responseHeaders.get(headerKey)) { | |
CookieManager.getInstance().setCookie(url, headerValue); | |
} | |
CookieSyncManager.getInstance().sync(); | |
} | |
} | |
@Override | |
public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) throws IOException { | |
if (uri == null || requestHeaders == null) { | |
throw new IllegalArgumentException("Argument is null"); | |
} | |
String url = uri.toString(); | |
Map<String, List<String>> res = new java.util.HashMap<String, List<String>>(); | |
String cookie = CookieManager.getInstance().getCookie(url); | |
if (cookie != null) { | |
res.put("Cookie", Arrays.asList(cookie)); | |
} | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment