Search in sources :

Example 11 with Headers

use of com.koushikdutta.async.http.Headers 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

Headers (com.koushikdutta.async.http.Headers)11 IOException (java.io.IOException)3 CookieManager (java.net.CookieManager)3 List (java.util.List)3 ByteBufferList (com.koushikdutta.async.ByteBufferList)2 DataEmitter (com.koushikdutta.async.DataEmitter)2 Ion (com.koushikdutta.ion.Ion)2 URI (java.net.URI)2 CertificateEncodingException (java.security.cert.CertificateEncodingException)2 CertificateException (java.security.cert.CertificateException)2 LineEmitter (com.koushikdutta.async.LineEmitter)1 StringCallback (com.koushikdutta.async.LineEmitter.StringCallback)1 DataCallback (com.koushikdutta.async.callback.DataCallback)1 TransformFuture (com.koushikdutta.async.future.TransformFuture)1 AsyncHttpRequestBody (com.koushikdutta.async.http.body.AsyncHttpRequestBody)1 CookieMiddleware (com.koushikdutta.ion.cookie.CookieMiddleware)1 HttpCookie (java.net.HttpCookie)1 ArrayList (java.util.ArrayList)1