Search in sources :

Example 16 with AsyncHttpGet

use of com.koushikdutta.async.http.AsyncHttpGet in project AndroidAsync by koush.

the class Issue59 method testIssue.

public void testIssue() throws Exception {
    AsyncHttpServer httpServer = new AsyncHttpServer();
    try {
        httpServer.get("/", new HttpServerRequestCallback() {

            @Override
            public void onRequest(AsyncHttpServerRequest request, final AsyncHttpServerResponse response) {
                // setting this to empty is a hacky way of telling the framework not to use
                // transfer-encoding. It will get removed.
                response.getHeaders().set("Transfer-Encoding", "");
                response.code(200);
                Util.writeAll(response, "foobarbeepboop".getBytes(), new CompletedCallback() {

                    @Override
                    public void onCompleted(Exception ex) {
                        response.end();
                    }
                });
            }
        });
        httpServer.listen(5959);
        AsyncHttpGet get = new AsyncHttpGet("http://localhost:5959/");
        get.setLogging("issue59", Log.VERBOSE);
        get.getHeaders().removeAll("Connection");
        get.getHeaders().removeAll("Accept-Encoding");
        assertEquals("foobarbeepboop", AsyncHttpClient.getDefaultInstance().executeString(get, null).get(1000, TimeUnit.MILLISECONDS));
    } finally {
        httpServer.stop();
        AsyncServer.getDefault().stop();
    }
}
Also used : AsyncHttpGet(com.koushikdutta.async.http.AsyncHttpGet) CompletedCallback(com.koushikdutta.async.callback.CompletedCallback) 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)

Example 17 with AsyncHttpGet

use of com.koushikdutta.async.http.AsyncHttpGet in project AndroidAsync by koush.

the class RedirectTests method testRelativeRedirect.

public void testRelativeRedirect() throws Exception {
    String ret = AsyncHttpClient.getDefaultInstance().executeString(new AsyncHttpGet("http://localhost:6003/foo/bar"), null).get();
    assertEquals(ret, "SUCCESS!");
    ret = AsyncHttpClient.getDefaultInstance().executeString(new AsyncHttpGet("http://localhost:6003/foo"), null).get();
    assertEquals(ret, "BORAT!");
    ret = AsyncHttpClient.getDefaultInstance().executeString(new AsyncHttpGet("http://localhost:6003/foo/poo"), null).get();
    assertEquals(ret, "SWEET!");
}
Also used : AsyncHttpGet(com.koushikdutta.async.http.AsyncHttpGet)

Aggregations

AsyncHttpGet (com.koushikdutta.async.http.AsyncHttpGet)17 AsyncHttpServer (com.koushikdutta.async.http.server.AsyncHttpServer)5 AsyncHttpServerRequest (com.koushikdutta.async.http.server.AsyncHttpServerRequest)5 AsyncHttpServerResponse (com.koushikdutta.async.http.server.AsyncHttpServerResponse)5 HttpServerRequestCallback (com.koushikdutta.async.http.server.HttpServerRequestCallback)4 AsyncServerSocket (com.koushikdutta.async.AsyncServerSocket)3 ByteBufferList (com.koushikdutta.async.ByteBufferList)3 CompletedCallback (com.koushikdutta.async.callback.CompletedCallback)3 AsyncHttpClient (com.koushikdutta.async.http.AsyncHttpClient)3 AsyncHttpResponse (com.koushikdutta.async.http.AsyncHttpResponse)3 CancellationException (java.util.concurrent.CancellationException)3 ExecutionException (java.util.concurrent.ExecutionException)3 Semaphore (java.util.concurrent.Semaphore)3 TimeoutException (java.util.concurrent.TimeoutException)3 Test (org.junit.Test)3 AsyncServer (com.koushikdutta.async.AsyncServer)2 File (java.io.File)2 AssetManager (android.content.res.AssetManager)1 Uri (android.net.Uri)1 DataEmitter (com.koushikdutta.async.DataEmitter)1