Search in sources :

Example 1 with LeakyBufferedInputStream

use of com.facebook.stetho.server.LeakyBufferedInputStream in project stetho by facebook.

the class LightHttpServer method serve.

public void serve(SocketLike socket) throws IOException {
    LeakyBufferedInputStream input = new LeakyBufferedInputStream(socket.getInput(), 1024);
    OutputStream output = socket.getOutput();
    HttpMessageReader reader = new HttpMessageReader(input);
    HttpMessageWriter writer = new HttpMessageWriter(new BufferedOutputStream(output));
    SocketLike anotherSocketLike = new SocketLike(socket, input);
    LightHttpRequest scratchRequest = new LightHttpRequest();
    LightHttpResponse scratchResponse = new LightHttpResponse();
    LightHttpRequest request;
    // expect the client to just close the connection.
    while ((request = readRequestMessage(scratchRequest, reader)) != null) {
        final LightHttpResponse response = scratchResponse;
        response.reset();
        // Note, if we're upgrading to websockets, this will block for the lifetime of the
        // websocket session...
        boolean keepGoing = dispatchToHandler(anotherSocketLike, request, response);
        if (!keepGoing) {
            // Orderly shutdown, ignore response and break the loop.
            break;
        }
        writeFullResponse(response, writer, output);
    }
}
Also used : SocketLike(com.facebook.stetho.server.SocketLike) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) LeakyBufferedInputStream(com.facebook.stetho.server.LeakyBufferedInputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

LeakyBufferedInputStream (com.facebook.stetho.server.LeakyBufferedInputStream)1 SocketLike (com.facebook.stetho.server.SocketLike)1 BufferedOutputStream (java.io.BufferedOutputStream)1 OutputStream (java.io.OutputStream)1