Search in sources :

Example 1 with Http2StreamFrame

use of io.netty.handler.codec.http2.Http2StreamFrame in project netty by netty.

the class Http2MultiplexCodec method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (!(msg instanceof Http2Frame)) {
        ctx.fireChannelRead(msg);
        return;
    }
    if (msg instanceof Http2StreamFrame) {
        Http2StreamFrame frame = (Http2StreamFrame) msg;
        int streamId = frame.streamId();
        Http2StreamChannel childChannel = childChannels.get(streamId);
        if (childChannel == null) {
            // TODO: Combine with DefaultHttp2ConnectionDecoder.shouldIgnoreHeadersOrDataFrame logic.
            ReferenceCountUtil.release(msg);
            throw new StreamException(streamId, STREAM_CLOSED, format("Received %s frame for an unknown stream %d", frame.name(), streamId));
        }
        fireChildReadAndRegister(childChannel, frame);
    } else if (msg instanceof Http2GoAwayFrame) {
        Http2GoAwayFrame goAwayFrame = (Http2GoAwayFrame) msg;
        for (PrimitiveEntry<Http2StreamChannel> entry : childChannels.entries()) {
            Http2StreamChannel childChannel = entry.value();
            int streamId = entry.key();
            if (streamId > goAwayFrame.lastStreamId() && isOutboundStream(server, streamId)) {
                childChannel.pipeline().fireUserEventTriggered(goAwayFrame.retainedDuplicate());
            }
        }
        goAwayFrame.release();
    } else {
        // It's safe to release, as UnsupportedMessageTypeException just calls msg.getClass()
        ReferenceCountUtil.release(msg);
        throw new UnsupportedMessageTypeException(msg);
    }
}
Also used : PrimitiveEntry(io.netty.util.collection.IntObjectMap.PrimitiveEntry) StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) UnsupportedMessageTypeException(io.netty.handler.codec.UnsupportedMessageTypeException)

Example 2 with Http2StreamFrame

use of io.netty.handler.codec.http2.Http2StreamFrame in project netty by netty.

the class Http2MultiplexHandler method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    parentReadInProgress = true;
    if (msg instanceof Http2StreamFrame) {
        if (msg instanceof Http2WindowUpdateFrame) {
            // We dont want to propagate update frames to the user
            return;
        }
        Http2StreamFrame streamFrame = (Http2StreamFrame) msg;
        DefaultHttp2FrameStream s = (DefaultHttp2FrameStream) streamFrame.stream();
        AbstractHttp2StreamChannel channel = (AbstractHttp2StreamChannel) s.attachment;
        if (msg instanceof Http2ResetFrame) {
            // Reset frames needs to be propagated via user events as these are not flow-controlled and so
            // must not be controlled by suppressing channel.read() on the child channel.
            channel.pipeline().fireUserEventTriggered(msg);
        // RST frames will also trigger closing of the streams which then will call
        // AbstractHttp2StreamChannel.streamClosed()
        } else {
            channel.fireChildRead(streamFrame);
        }
        return;
    }
    if (msg instanceof Http2GoAwayFrame) {
        // goaway frames will also trigger closing of the streams which then will call
        // AbstractHttp2StreamChannel.streamClosed()
        onHttp2GoAwayFrame(ctx, (Http2GoAwayFrame) msg);
    }
    // Send everything down the pipeline
    ctx.fireChannelRead(msg);
}
Also used : DefaultHttp2FrameStream(io.netty.handler.codec.http2.Http2FrameCodec.DefaultHttp2FrameStream)

Aggregations

UnsupportedMessageTypeException (io.netty.handler.codec.UnsupportedMessageTypeException)1 StreamException (io.netty.handler.codec.http2.Http2Exception.StreamException)1 DefaultHttp2FrameStream (io.netty.handler.codec.http2.Http2FrameCodec.DefaultHttp2FrameStream)1 PrimitiveEntry (io.netty.util.collection.IntObjectMap.PrimitiveEntry)1