use of com.koushikdutta.ion.cookie.CookieMiddleware in project ion by koush.
the class HttpTests method testCookie.
public void testCookie() throws Exception {
Ion ion = Ion.getDefault(getContext());
ion.getCookieMiddleware().clear();
ion.build(getContext()).load("http://google.com").asString().get();
for (HttpCookie cookie : ion.getCookieMiddleware().getCookieStore().get(URI.create("http://www.google.com"))) {
Log.i("CookieTest", cookie.getName() + ": " + cookie.getValue());
}
assertTrue(ion.getCookieMiddleware().getCookieManager().get(URI.create("http://www.google.com/test/path"), new Multimap()).size() > 0);
CookieMiddleware deserialize = new CookieMiddleware(ion);
assertTrue(deserialize.getCookieManager().get(URI.create("http://www.google.com/test/path"), new Multimap()).size() > 0);
}
use of com.koushikdutta.ion.cookie.CookieMiddleware in project ion by koush.
the class CookieTests method testReinit.
public void testReinit() throws Exception {
CookieMiddleware middleware = Ion.getDefault(getContext()).getCookieMiddleware();
Ion ion = Ion.getDefault(getContext());
ion.getCookieMiddleware().clear();
Headers headers = new Headers();
headers.set("Set-Cookie", "foo=bar");
URI uri = URI.create("http://example.com");
middleware.put(uri, headers);
headers.set("Set-Cookie", "poop=scoop");
middleware.put(uri, headers);
headers.set("Set-Cookie", "foo=goop");
middleware.put(uri, headers);
middleware.reinit();
CookieManager manager = middleware.getCookieManager();
Headers newHeaders = new Headers();
Map<String, List<String>> cookies = manager.get(uri, newHeaders.getMultiMap());
manager.get(uri, cookies);
CookieMiddleware.addCookies(cookies, newHeaders);
assertTrue(newHeaders.get("Cookie").contains("foo=goop"));
assertTrue(newHeaders.get("Cookie").contains("poop=scoop"));
assertFalse(newHeaders.get("Cookie").contains("bar"));
}
Aggregations