Search in sources :

Example 1 with StreamedAsyncHandler

use of org.asynchttpclient.handler.StreamedAsyncHandler in project async-http-client by AsyncHttpClient.

the class HttpHandler method handleChunk.

private //
void handleChunk(//
HttpContent chunk, //
final Channel channel, //
final NettyResponseFuture<?> future, AsyncHandler<?> handler) throws IOException, Exception {
    boolean abort = false;
    boolean last = chunk instanceof LastHttpContent;
    // Netty 4: the last chunk is not empty
    if (last) {
        LastHttpContent lastChunk = (LastHttpContent) chunk;
        HttpHeaders trailingHeaders = lastChunk.trailingHeaders();
        if (!trailingHeaders.isEmpty()) {
            abort = handler.onHeadersReceived(new HttpResponseHeaders(trailingHeaders, true)) == State.ABORT;
        }
    }
    ByteBuf buf = chunk.content();
    if (!abort && !(handler instanceof StreamedAsyncHandler) && (buf.readableBytes() > 0 || last)) {
        HttpResponseBodyPart bodyPart = config.getResponseBodyPartFactory().newResponseBodyPart(buf, last);
        abort = handler.onBodyPartReceived(bodyPart) == State.ABORT;
    }
    if (abort || last) {
        boolean keepAlive = !abort && future.isKeepAlive();
        finishUpdate(future, channel, keepAlive, !last);
    }
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) HttpResponseHeaders(org.asynchttpclient.HttpResponseHeaders) StreamedAsyncHandler(org.asynchttpclient.handler.StreamedAsyncHandler) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) ByteBuf(io.netty.buffer.ByteBuf) HttpResponseBodyPart(org.asynchttpclient.HttpResponseBodyPart)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)1 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)1 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)1 HttpResponseBodyPart (org.asynchttpclient.HttpResponseBodyPart)1 HttpResponseHeaders (org.asynchttpclient.HttpResponseHeaders)1 StreamedAsyncHandler (org.asynchttpclient.handler.StreamedAsyncHandler)1