Search in sources :

Example 1 with StreamBufferingEncoder

use of io.netty.handler.codec.http2.StreamBufferingEncoder in project rest.li by linkedin.

the class Http2StreamCodecBuilder method build.

@Override
public Http2StreamCodec build() {
    ObjectUtil.checkNotNull(_connection, "connection");
    ObjectUtil.checkPositive(_maxHeaderSize, "maxHeaderSize");
    Http2HeadersDecoder headerDecoder = new DefaultHttp2HeadersDecoder(_maxHeaderSize, Http2CodecUtil.DEFAULT_HEADER_TABLE_SIZE, isValidateHeaders(), INITIAL_HUFFMAN_DECODE_CAPACITY);
    Http2FrameReader reader = new DefaultHttp2FrameReader(headerDecoder);
    Http2FrameWriter writer = new DefaultHttp2FrameWriter(headerSensitivityDetector());
    if (frameLogger() != null) {
        reader = new Http2InboundFrameLogger(reader, frameLogger());
        writer = new Http2OutboundFrameLogger(writer, frameLogger());
    }
    Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(_connection, writer);
    boolean encoderEnforceMaxConcurrentStreams = encoderEnforceMaxConcurrentStreams();
    if (encoderEnforceMaxConcurrentStreams) {
        if (_connection.isServer()) {
            encoder.close();
            reader.close();
            throw new IllegalArgumentException("encoderEnforceMaxConcurrentStreams: " + encoderEnforceMaxConcurrentStreams + " not supported for server");
        }
        encoder = new StreamBufferingEncoder(encoder);
    }
    Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(_connection, encoder, reader);
    super.codec(decoder, encoder);
    return super.build();
}
Also used : Http2InboundFrameLogger(io.netty.handler.codec.http2.Http2InboundFrameLogger) Http2FrameReader(io.netty.handler.codec.http2.Http2FrameReader) DefaultHttp2FrameReader(io.netty.handler.codec.http2.DefaultHttp2FrameReader) StreamBufferingEncoder(io.netty.handler.codec.http2.StreamBufferingEncoder) DefaultHttp2ConnectionDecoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder) Http2OutboundFrameLogger(io.netty.handler.codec.http2.Http2OutboundFrameLogger) Http2HeadersDecoder(io.netty.handler.codec.http2.Http2HeadersDecoder) DefaultHttp2HeadersDecoder(io.netty.handler.codec.http2.DefaultHttp2HeadersDecoder) DefaultHttp2FrameWriter(io.netty.handler.codec.http2.DefaultHttp2FrameWriter) DefaultHttp2ConnectionEncoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder) Http2ConnectionDecoder(io.netty.handler.codec.http2.Http2ConnectionDecoder) DefaultHttp2ConnectionDecoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder) Http2FrameWriter(io.netty.handler.codec.http2.Http2FrameWriter) DefaultHttp2FrameWriter(io.netty.handler.codec.http2.DefaultHttp2FrameWriter) DefaultHttp2HeadersDecoder(io.netty.handler.codec.http2.DefaultHttp2HeadersDecoder) Http2ConnectionEncoder(io.netty.handler.codec.http2.Http2ConnectionEncoder) DefaultHttp2ConnectionEncoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder) DefaultHttp2FrameReader(io.netty.handler.codec.http2.DefaultHttp2FrameReader)

Example 2 with StreamBufferingEncoder

use of io.netty.handler.codec.http2.StreamBufferingEncoder in project grpc-java by grpc.

the class NettyClientHandler method newHandler.

@VisibleForTesting
static NettyClientHandler newHandler(Http2Connection connection, Http2FrameReader frameReader, Http2FrameWriter frameWriter, ClientTransportLifecycleManager lifecycleManager, KeepAliveManager keepAliveManager, int flowControlWindow, int maxHeaderListSize, Ticker ticker) {
    Preconditions.checkNotNull(connection, "connection");
    Preconditions.checkNotNull(frameReader, "frameReader");
    Preconditions.checkNotNull(lifecycleManager, "lifecycleManager");
    Preconditions.checkArgument(flowControlWindow > 0, "flowControlWindow must be positive");
    Preconditions.checkArgument(maxHeaderListSize > 0, "maxHeaderListSize must be positive");
    Preconditions.checkNotNull(ticker, "ticker");
    Http2FrameLogger frameLogger = new Http2FrameLogger(LogLevel.DEBUG, NettyClientHandler.class);
    frameReader = new Http2InboundFrameLogger(frameReader, frameLogger);
    frameWriter = new Http2OutboundFrameLogger(frameWriter, frameLogger);
    StreamBufferingEncoder encoder = new StreamBufferingEncoder(new DefaultHttp2ConnectionEncoder(connection, frameWriter));
    // Create the local flow controller configured to auto-refill the connection window.
    connection.local().flowController(new DefaultHttp2LocalFlowController(connection, DEFAULT_WINDOW_UPDATE_RATIO, true));
    // TODO(ejona): swap back to DefaultHttp2Connection with Netty-4.1.9
    Http2ConnectionDecoder decoder = new FixedHttp2ConnectionDecoder(connection, encoder, frameReader);
    Http2Settings settings = new Http2Settings();
    settings.pushEnabled(false);
    settings.initialWindowSize(flowControlWindow);
    settings.maxConcurrentStreams(0);
    settings.maxHeaderListSize(maxHeaderListSize);
    return new NettyClientHandler(decoder, encoder, settings, lifecycleManager, keepAliveManager, ticker);
}
Also used : Http2ConnectionDecoder(io.netty.handler.codec.http2.Http2ConnectionDecoder) Http2InboundFrameLogger(io.netty.handler.codec.http2.Http2InboundFrameLogger) StreamBufferingEncoder(io.netty.handler.codec.http2.StreamBufferingEncoder) Http2FrameLogger(io.netty.handler.codec.http2.Http2FrameLogger) DefaultHttp2LocalFlowController(io.netty.handler.codec.http2.DefaultHttp2LocalFlowController) Http2OutboundFrameLogger(io.netty.handler.codec.http2.Http2OutboundFrameLogger) Http2Settings(io.netty.handler.codec.http2.Http2Settings) DefaultHttp2ConnectionEncoder(io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

DefaultHttp2ConnectionEncoder (io.netty.handler.codec.http2.DefaultHttp2ConnectionEncoder)2 Http2ConnectionDecoder (io.netty.handler.codec.http2.Http2ConnectionDecoder)2 Http2InboundFrameLogger (io.netty.handler.codec.http2.Http2InboundFrameLogger)2 Http2OutboundFrameLogger (io.netty.handler.codec.http2.Http2OutboundFrameLogger)2 StreamBufferingEncoder (io.netty.handler.codec.http2.StreamBufferingEncoder)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 DefaultHttp2ConnectionDecoder (io.netty.handler.codec.http2.DefaultHttp2ConnectionDecoder)1 DefaultHttp2FrameReader (io.netty.handler.codec.http2.DefaultHttp2FrameReader)1 DefaultHttp2FrameWriter (io.netty.handler.codec.http2.DefaultHttp2FrameWriter)1 DefaultHttp2HeadersDecoder (io.netty.handler.codec.http2.DefaultHttp2HeadersDecoder)1 DefaultHttp2LocalFlowController (io.netty.handler.codec.http2.DefaultHttp2LocalFlowController)1 Http2ConnectionEncoder (io.netty.handler.codec.http2.Http2ConnectionEncoder)1 Http2FrameLogger (io.netty.handler.codec.http2.Http2FrameLogger)1 Http2FrameReader (io.netty.handler.codec.http2.Http2FrameReader)1 Http2FrameWriter (io.netty.handler.codec.http2.Http2FrameWriter)1 Http2HeadersDecoder (io.netty.handler.codec.http2.Http2HeadersDecoder)1 Http2Settings (io.netty.handler.codec.http2.Http2Settings)1