use of com.koushikdutta.async.http.server.AsyncProxyServer in project ion by koush.
the class HttpTests method testProxy.
public void testProxy() throws Exception {
wasProxied = false;
final AsyncServer proxyServer = new AsyncServer();
try {
AsyncProxyServer httpServer = new AsyncProxyServer(proxyServer) {
@Override
protected boolean onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
wasProxied = true;
return super.onRequest(request, response);
}
};
AsyncServerSocket s = httpServer.listen(proxyServer, 0);
Future<String> ret = Ion.with(getContext()).load("http://www.clockworkmod.com").proxy("localhost", s.getLocalPort()).asString();
String data;
assertNotNull(data = ret.get(10000, TimeUnit.MILLISECONDS));
assertTrue(data.contains("ClockworkMod"));
assertTrue(wasProxied);
} finally {
proxyServer.stop();
}
}
use of com.koushikdutta.async.http.server.AsyncProxyServer in project AndroidAsync by koush.
the class HttpClientTests method testProxy.
public void testProxy() throws Exception {
wasProxied = false;
final AsyncServer proxyServer = new AsyncServer();
try {
AsyncProxyServer httpServer = new AsyncProxyServer(proxyServer) {
@Override
protected boolean onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
wasProxied = true;
return super.onRequest(request, response);
}
};
AsyncServerSocket socket = httpServer.listen(proxyServer, 0);
// client.getSocketMiddleware().enableProxy("localhost", 5555);
AsyncHttpGet get = new AsyncHttpGet("http://www.clockworkmod.com");
get.enableProxy("localhost", socket.getLocalPort());
Future<String> ret = client.executeString(get, null);
String data;
assertNotNull(data = ret.get(TIMEOUT, TimeUnit.MILLISECONDS));
assertTrue(data.contains("ClockworkMod"));
assertTrue(wasProxied);
} finally {
proxyServer.stop();
}
}
Aggregations