Search in sources :

Example 66 with Http2Stream

use of io.netty.handler.codec.http2.Http2Stream in project micronaut-core by micronaut-projects.

the class StreamingInboundHttp2ToHttpAdapter method onDataRead.

@Override
public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream) throws Http2Exception {
    Http2Stream stream = connection.stream(streamId);
    HttpMessage msg = getMessage(stream);
    if (msg == null) {
        throw connectionError(PROTOCOL_ERROR, "Data Frame received for unknown stream id %d", streamId);
    }
    AtomicInteger dataRead = getDataRead(stream);
    final int dataReadableBytes = data.readableBytes();
    final int readSoFar = dataRead.getAndAdd(dataReadableBytes);
    if (readSoFar > maxContentLength - dataReadableBytes) {
        throw connectionError(INTERNAL_ERROR, "Content length exceeded max of %d for stream id %d", maxContentLength, streamId);
    }
    if (endOfStream) {
        // will be released by HttpStreamsHandler
        if (dataReadableBytes > 0) {
            final DefaultLastHttpContent content = new DefaultLastHttp2Content(data.retain(), stream);
            fireChannelRead(ctx, content, stream);
        } else {
            fireChannelRead(ctx, new DefaultLastHttp2Content(Unpooled.EMPTY_BUFFER, stream), stream);
        }
    } else {
        // will be released by HttpStreamsHandler
        final DefaultHttp2Content content = new DefaultHttp2Content(data.retain(), stream);
        fireChannelRead(ctx, content, stream);
    }
    // All bytes have been processed.
    return dataReadableBytes + padding;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Example 67 with Http2Stream

use of io.netty.handler.codec.http2.Http2Stream in project micronaut-core by micronaut-projects.

the class StreamingInboundHttp2ToHttpAdapter method onRstStreamRead.

@Override
public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) {
    Http2Stream stream = connection.stream(streamId);
    HttpMessage msg = getMessage(stream);
    if (msg != null) {
        onRstStreamRead(stream, msg);
    }
    // discard stream since it has been reset
    stream.close();
}
Also used : Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Example 68 with Http2Stream

use of io.netty.handler.codec.http2.Http2Stream in project micronaut-core by micronaut-projects.

the class StreamingInboundHttp2ToHttpAdapter method onHeadersRead.

@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int padding, boolean endOfStream) throws Http2Exception {
    Http2Stream stream = connection.stream(streamId);
    HttpMessage msg = processHeadersBegin(ctx, stream, headers, true, true);
    if (msg != null) {
        processHeadersEnd(ctx, stream, msg, endOfStream);
    }
}
Also used : Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Aggregations

Http2Stream (io.netty.handler.codec.http2.Http2Stream)44 Http2Exception (io.netty.handler.codec.http2.Http2Exception)15 ByteBuf (io.netty.buffer.ByteBuf)12 Test (org.junit.Test)12 Test (org.junit.jupiter.api.Test)9 Http2Connection (io.netty.handler.codec.http2.Http2Connection)8 ChannelFuture (io.netty.channel.ChannelFuture)7 Http2StreamVisitor (io.netty.handler.codec.http2.Http2StreamVisitor)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 Metadata (io.grpc.Metadata)6 Http2LocalFlowController (io.netty.handler.codec.http2.Http2LocalFlowController)6 Status (io.grpc.Status)5 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)5 StreamException (io.netty.handler.codec.http2.Http2Exception.StreamException)5 Channel (io.netty.channel.Channel)4 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)4 Http2Headers (io.netty.handler.codec.http2.Http2Headers)4 AsyncResult (io.vertx.core.AsyncResult)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Bootstrap (io.netty.bootstrap.Bootstrap)3