use of com.koushikdutta.async.http.server.AsyncHttpServerResponse in project ion by koush.
the class HttpTests method testPut.
public void testPut() throws Exception {
AsyncHttpServer httpServer = new AsyncHttpServer();
try {
httpServer.addAction("PUT", "/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, final AsyncHttpServerResponse response) {
response.send(request.getMethod());
}
});
httpServer.listen(Ion.getDefault(getContext()).getServer(), 5555);
Future<String> ret = Ion.with(getContext()).load("PUT", "http://localhost:5555/").asString();
assertEquals(ret.get(), "PUT");
} finally {
httpServer.stop();
}
}
use of com.koushikdutta.async.http.server.AsyncHttpServerResponse 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.AsyncHttpServerResponse in project ion by koush.
the class StreamTests method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
AsyncHttpServer server = new AsyncHttpServer();
port = server.listen(0).getLocalPort();
server.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, final AsyncHttpServerResponse response) {
response.code(200);
ByteBuffer b = ByteBufferList.obtain(random.length);
b.put(random);
b.flip();
ByteBufferList list = new ByteBufferList(b);
Util.writeAll(response, list, new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
response.end();
}
});
}
});
}
Aggregations