Search in sources :

Example 21 with HttpServerRequestCallback

use of com.koushikdutta.async.http.server.HttpServerRequestCallback 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)

Aggregations

AsyncHttpServerRequest (com.koushikdutta.async.http.server.AsyncHttpServerRequest)21 AsyncHttpServerResponse (com.koushikdutta.async.http.server.AsyncHttpServerResponse)21 HttpServerRequestCallback (com.koushikdutta.async.http.server.HttpServerRequestCallback)21 AsyncHttpServer (com.koushikdutta.async.http.server.AsyncHttpServer)20 CompletedCallback (com.koushikdutta.async.callback.CompletedCallback)6 MultipartFormDataBody (com.koushikdutta.async.http.body.MultipartFormDataBody)4 JsonObject (com.google.gson.JsonObject)3 AsyncHttpGet (com.koushikdutta.async.http.AsyncHttpGet)3 Part (com.koushikdutta.async.http.body.Part)3 AsyncServer (com.koushikdutta.async.AsyncServer)2 ByteBufferList (com.koushikdutta.async.ByteBufferList)2 UrlEncodedFormBody (com.koushikdutta.async.http.body.UrlEncodedFormBody)2 HeadersResponse (com.koushikdutta.ion.HeadersResponse)2 File (java.io.File)2 KeyStore (java.security.KeyStore)2 Semaphore (java.util.concurrent.Semaphore)2 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)2 SSLContext (javax.net.ssl.SSLContext)2 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)2 JsonParseException (com.google.gson.JsonParseException)1