Search in sources :

Example 1 with CookieMiddleware

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);
}
Also used : Multimap(com.koushikdutta.async.http.Multimap) CookieMiddleware(com.koushikdutta.ion.cookie.CookieMiddleware) Ion(com.koushikdutta.ion.Ion) HttpCookie(java.net.HttpCookie)

Example 2 with CookieMiddleware

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"));
}
Also used : CookieMiddleware(com.koushikdutta.ion.cookie.CookieMiddleware) Headers(com.koushikdutta.async.http.Headers) Ion(com.koushikdutta.ion.Ion) List(java.util.List) URI(java.net.URI) CookieManager(java.net.CookieManager)

Aggregations

Ion (com.koushikdutta.ion.Ion)2 CookieMiddleware (com.koushikdutta.ion.cookie.CookieMiddleware)2 Headers (com.koushikdutta.async.http.Headers)1 Multimap (com.koushikdutta.async.http.Multimap)1 CookieManager (java.net.CookieManager)1 HttpCookie (java.net.HttpCookie)1 URI (java.net.URI)1 List (java.util.List)1