use of com.koushikdutta.ion.Ion in project ion by koush.
the class CookieTests method testCookies.
public void testCookies() throws Exception {
Ion ion = Ion.getDefault(getContext());
ion.getCookieMiddleware().clear();
CookieManager manager = new CookieManager(null, null);
Headers headers = new Headers();
headers.set("Set-Cookie", "foo=bar");
URI uri = URI.create("http://example.com");
manager.put(uri, headers.getMultiMap());
headers.set("Set-Cookie", "poop=scoop");
manager.put(uri, headers.getMultiMap());
headers.set("Set-Cookie", "foo=goop");
manager.put(uri, headers.getMultiMap());
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"));
}
use of com.koushikdutta.ion.Ion 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.Ion in project ion by koush.
the class SelfSignedCertificateTests method testKeys.
public void testKeys() throws Exception {
KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509");
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(getContext().getResources().openRawResource(R.raw.keystore), "storepass".toCharArray());
kmf.init(ks, "storepass".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore ts = KeyStore.getInstance(KeyStore.getDefaultType());
ts.load(getContext().getResources().openRawResource(R.raw.keystore), "storepass".toCharArray());
tmf.init(ts);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
AsyncHttpServer httpServer = new AsyncHttpServer();
httpServer.listenSecure(8888, sslContext);
httpServer.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
response.send("hello");
}
});
Thread.sleep(1000);
Ion ion = Ion.getInstance(getContext(), "CustomSSL");
ion.getHttpClient().getSSLSocketMiddleware().setSSLContext(sslContext);
ion.getHttpClient().getSSLSocketMiddleware().setTrustManagers(tmf.getTrustManagers());
ion.build(getContext()).load("https://localhost:8888/").asString().get();
}
use of com.koushikdutta.ion.Ion 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