Search in sources :

Example 1 with HeadersCallback

use of com.koushikdutta.ion.HeadersCallback 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();
    }
}
Also used : HttpServerRequestCallback(com.koushikdutta.async.http.server.HttpServerRequestCallback) AsyncHttpServerRequest(com.koushikdutta.async.http.server.AsyncHttpServerRequest) AsyncHttpServer(com.koushikdutta.async.http.server.AsyncHttpServer) AsyncHttpServerResponse(com.koushikdutta.async.http.server.AsyncHttpServerResponse) HeadersCallback(com.koushikdutta.ion.HeadersCallback) HeadersResponse(com.koushikdutta.ion.HeadersResponse)

Aggregations

AsyncHttpServer (com.koushikdutta.async.http.server.AsyncHttpServer)1 AsyncHttpServerRequest (com.koushikdutta.async.http.server.AsyncHttpServerRequest)1 AsyncHttpServerResponse (com.koushikdutta.async.http.server.AsyncHttpServerResponse)1 HttpServerRequestCallback (com.koushikdutta.async.http.server.HttpServerRequestCallback)1 HeadersCallback (com.koushikdutta.ion.HeadersCallback)1 HeadersResponse (com.koushikdutta.ion.HeadersResponse)1