Search in sources :

Example 1 with DefaultHttp2FrameStream

use of io.netty.handler.codec.http2.Http2FrameCodec.DefaultHttp2FrameStream 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)

Example 2 with DefaultHttp2FrameStream

use of io.netty.handler.codec.http2.Http2FrameCodec.DefaultHttp2FrameStream in project netty by netty.

the class Http2MultiplexHandler method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, final Throwable cause) throws Exception {
    if (cause instanceof Http2FrameStreamException) {
        Http2FrameStreamException exception = (Http2FrameStreamException) cause;
        Http2FrameStream stream = exception.stream();
        AbstractHttp2StreamChannel childChannel = (AbstractHttp2StreamChannel) ((DefaultHttp2FrameStream) stream).attachment;
        try {
            childChannel.pipeline().fireExceptionCaught(cause.getCause());
        } finally {
            childChannel.unsafe().closeForcibly();
        }
        return;
    }
    if (cause.getCause() instanceof SSLException) {
        forEachActiveStream(new Http2FrameStreamVisitor() {

            @Override
            public boolean visit(Http2FrameStream stream) {
                AbstractHttp2StreamChannel childChannel = (AbstractHttp2StreamChannel) ((DefaultHttp2FrameStream) stream).attachment;
                childChannel.pipeline().fireExceptionCaught(cause);
                return true;
            }
        });
    }
    ctx.fireExceptionCaught(cause);
}
Also used : DefaultHttp2FrameStream(io.netty.handler.codec.http2.Http2FrameCodec.DefaultHttp2FrameStream) DefaultHttp2FrameStream(io.netty.handler.codec.http2.Http2FrameCodec.DefaultHttp2FrameStream) SSLException(javax.net.ssl.SSLException)

Example 3 with DefaultHttp2FrameStream

use of io.netty.handler.codec.http2.Http2FrameCodec.DefaultHttp2FrameStream in project netty by netty.

the class Http2MultiplexHandler method userEventTriggered.

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof Http2FrameStreamEvent) {
        Http2FrameStreamEvent event = (Http2FrameStreamEvent) evt;
        DefaultHttp2FrameStream stream = (DefaultHttp2FrameStream) event.stream();
        if (event.type() == Http2FrameStreamEvent.Type.State) {
            switch(stream.state()) {
                case HALF_CLOSED_LOCAL:
                    if (stream.id() != Http2CodecUtil.HTTP_UPGRADE_STREAM_ID) {
                        // Ignore everything which was not caused by an upgrade
                        break;
                    }
                // fall-through
                case HALF_CLOSED_REMOTE:
                // fall-through
                case OPEN:
                    if (stream.attachment != null) {
                        // ignore if child channel was already created.
                        break;
                    }
                    final AbstractHttp2StreamChannel ch;
                    // We need to handle upgrades special when on the client side.
                    if (stream.id() == Http2CodecUtil.HTTP_UPGRADE_STREAM_ID && !isServer(ctx)) {
                        // We must have an upgrade handler or else we can't handle the stream
                        if (upgradeStreamHandler == null) {
                            throw connectionError(INTERNAL_ERROR, "Client is misconfigured for upgrade requests");
                        }
                        ch = new Http2MultiplexHandlerStreamChannel(stream, upgradeStreamHandler);
                        ch.closeOutbound();
                    } else {
                        ch = new Http2MultiplexHandlerStreamChannel(stream, inboundStreamHandler);
                    }
                    ChannelFuture future = ctx.channel().eventLoop().register(ch);
                    if (future.isDone()) {
                        registerDone(future);
                    } else {
                        future.addListener(CHILD_CHANNEL_REGISTRATION_LISTENER);
                    }
                    break;
                case CLOSED:
                    AbstractHttp2StreamChannel channel = (AbstractHttp2StreamChannel) stream.attachment;
                    if (channel != null) {
                        channel.streamClosed();
                    }
                    break;
                default:
                    // ignore for now
                    break;
            }
        }
        return;
    }
    ctx.fireUserEventTriggered(evt);
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) DefaultHttp2FrameStream(io.netty.handler.codec.http2.Http2FrameCodec.DefaultHttp2FrameStream)

Aggregations

DefaultHttp2FrameStream (io.netty.handler.codec.http2.Http2FrameCodec.DefaultHttp2FrameStream)3 ChannelFuture (io.netty.channel.ChannelFuture)1 SSLException (javax.net.ssl.SSLException)1