use of com.koushikdutta.async.http.server.AsyncHttpServer in project ion by koush.
the class AuthTests method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
httpServer = new AsyncHttpServer();
httpServer.listen(5555);
}
use of com.koushikdutta.async.http.server.AsyncHttpServer in project ion by koush.
the class HeadersTests method testHeaders.
public void testHeaders() throws Exception {
gotHeaders = false;
AsyncHttpServer httpServer = new AsyncHttpServer();
try {
httpServer.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
response.send("hello");
}
});
httpServer.listen(Ion.getDefault(getContext()).getServer(), 5555);
Ion.with(getContext()).load("http://localhost:5555/").onHeaders(new HeadersCallback() {
@Override
public void onHeaders(HeadersResponse headers) {
assertEquals(headers.code(), 200);
gotHeaders = true;
}
}).asString().get();
assertTrue(gotHeaders);
} finally {
httpServer.stop();
Ion.getDefault(getContext()).getServer().stop();
}
}
use of com.koushikdutta.async.http.server.AsyncHttpServer 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.AsyncHttpServer 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();
}
});
}
});
}
use of com.koushikdutta.async.http.server.AsyncHttpServer in project AndroidAsync by koush.
the class MultipartTests method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
httpServer = new AsyncHttpServer();
httpServer.setErrorCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
fail();
}
});
httpServer.listen(AsyncServer.getDefault(), 5000);
httpServer.post("/", new HttpServerRequestCallback() {
int gotten = 0;
@Override
public void onRequest(final AsyncHttpServerRequest request, final AsyncHttpServerResponse response) {
final MultipartFormDataBody body = (MultipartFormDataBody) request.getBody();
body.setMultipartCallback(new MultipartCallback() {
@Override
public void onPart(Part part) {
if (part.isFile()) {
body.setDataCallback(new DataCallback() {
@Override
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
gotten += bb.remaining();
bb.recycle();
}
});
}
}
});
request.setEndCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
response.send(body.getField("baz") + gotten + body.getField("foo"));
}
});
}
});
}
Aggregations