public HttpToHttp2ConnectionHandler(IHttp2ConnectionDecoder decoder, IHttp2ConnectionEncoder encoder,
                                     Http2Settings initialSettings, bool validateHeaders,
                                     bool decoupleCloseAndGoAway)
     : base(decoder, encoder, initialSettings, decoupleCloseAndGoAway)
 {
     _validateHeaders = validateHeaders;
 }
Ejemplo n.º 2
0
 protected override Http2FrameCodec Build(IHttp2ConnectionDecoder decoder, IHttp2ConnectionEncoder encoder, Http2Settings initialSettings)
 {
     return(new Http2FrameCodec(encoder, decoder, initialSettings, DecoupleCloseAndGoAway)
     {
         GracefulShutdownTimeout = GracefulShutdownTimeout
     });
 }
Ejemplo n.º 3
0
        public StreamBufferingEncoder(IHttp2ConnectionEncoder encoder, int initialMaxConcurrentStreams)
            : base(encoder)
        {
            _pendingStreams = new SortedDictionary <int, PendingStream>();

            _maxConcurrentStreams = initialMaxConcurrentStreams;
            Connection.AddListener(new DelegatingConnectionAdapter(this));
        }
 public Http2ControlFrameLimitEncoder(IHttp2ConnectionEncoder encoder, int maxOutstandingControlFrames)
     : base(encoder)
 {
     if ((uint)(maxOutstandingControlFrames - 1) > SharedConstants.TooBigOrNegative)
     {
         ThrowHelper.ThrowArgumentException_Positive(maxOutstandingControlFrames, ExceptionArgument.maxOutstandingControlFrames);
     }
     _maxOutstandingControlFrames = maxOutstandingControlFrames;
 }
        public DecoratingHttp2ConnectionEncoder(IHttp2ConnectionEncoder encoder)
            : base(encoder)
        {
            if (encoder is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.encoder);
            }

            _innerEncoder = encoder;
        }
        private static void WriteHeaders(IChannelHandlerContext ctx, IHttp2ConnectionEncoder encoder, int streamId,
                                         HttpHeaders headers, IHttp2Headers http2Headers, bool endStream,
                                         SimplePromiseAggregator promiseAggregator)
        {
            int dependencyId = headers.GetInt(
                HttpConversionUtil.ExtensionHeaderNames.StreamDependencyId, 0);
            short weight = headers.GetShort(
                HttpConversionUtil.ExtensionHeaderNames.StreamWeight, Http2CodecUtil.DefaultPriorityWeight);

            _ = encoder.WriteHeadersAsync(ctx, streamId, http2Headers, dependencyId, weight, false,
                                          0, endStream, promiseAggregator.NewPromise());
        }
Ejemplo n.º 7
0
        public Http2FrameCodec(IHttp2ConnectionEncoder encoder, IHttp2ConnectionDecoder decoder, Http2Settings initialSettings, bool decoupleCloseAndGoAway)
            : base(decoder, encoder, initialSettings, decoupleCloseAndGoAway)
        {
            _frameStreamToInitializeMap = new ConcurrentDictionary <int, DefaultHttp2FrameStream>();

            decoder.FrameListener = new FrameListener(this);
            var connection = Connection;

            connection.AddListener(new ConnectionListener(this));
            connection.Remote.FlowController.Listener(new Http2RemoteFlowControllerListener(this));
            _streamKey  = connection.NewKey();
            _upgradeKey = connection.NewKey();
            _initialFlowControlWindowSize = initialSettings.InitialWindowSize();
        }
        /// <summary>Create a new instance.</summary>
        /// <param name="connection">The <see cref="IHttp2Connection"/> associated with this decoder.</param>
        /// <param name="encoder">The <see cref="IHttp2ConnectionEncoder"/> associated with this decoder.</param>
        /// <param name="frameReader">Responsible for reading/parsing the raw frames. As opposed to this object which applies
        /// h2 semantics on top of the frames.</param>
        /// <param name="requestVerifier">Determines if push promised streams are valid.</param>
        /// <param name="autoAckSettings"><c>false</c> to disable automatically applying and sending settings acknowledge frame.
        /// The <paramref name="encoder"/> is expected to be an instance of
        /// <see cref="IHttp2SettingsReceivedConsumer"/> and will apply the earliest received but not yet
        /// ACKed SETTINGS when writing the SETTINGS ACKs. <c>true</c> to enable automatically
        /// applying and sending settings acknowledge frame.</param>
        /// <param name="autoAckPing"><c>false</c> to disable automatically sending ping acknowledge frame. <c>true</c> to enable
        /// automatically sending ping ack frame.</param>
        public DefaultHttp2ConnectionDecoder(IHttp2Connection connection,
                                             IHttp2ConnectionEncoder encoder, IHttp2FrameReader frameReader, IHttp2PromisedRequestVerifier requestVerifier,
                                             bool autoAckSettings, bool autoAckPing)
        {
            if (connection is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.connection);
            }
            if (frameReader is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.frameReader);
            }
            if (encoder is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.encoder);
            }
            if (requestVerifier is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.requestVerifier);
            }

            _autoAckPing = autoAckPing;
            if (autoAckSettings)
            {
                _settingsReceivedConsumer = null;
            }
            else
            {
                var receivedConsumer = encoder as IHttp2SettingsReceivedConsumer;
                if (receivedConsumer is null)
                {
                    ThrowHelper.ThrowInvalidOperationException_disabling_autoAckSettings_requires_encoder_IHttp2SettingsReceivedConsumer();
                }
                _settingsReceivedConsumer = receivedConsumer;
            }
            _connection      = connection;
            _frameReader     = frameReader;
            _encoder         = encoder;
            _requestVerifier = requestVerifier;
            var connLocal = connection.Local;

            if (connLocal.FlowController is null)
            {
                connLocal.FlowController = new DefaultHttp2LocalFlowController(connection);
            }
            _ = connLocal.FlowController.FrameWriter(encoder.FrameWriter);

            _internalFrameListener = new PrefaceFrameListener(this);
        }
Ejemplo n.º 9
0
 public Http2ConnectionHandler(IHttp2ConnectionDecoder decoder, IHttp2ConnectionEncoder encoder, Http2Settings initialSettings, bool decoupleCloseAndGoAway)
 {
     if (initialSettings is null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.initialSettings);
     }
     if (decoder is null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.decoder);
     }
     if (encoder is null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.encoder);
     }
     _initialSettings        = initialSettings;
     _decoder                = decoder;
     _encoder                = encoder;
     _decoupleCloseAndGoAway = decoupleCloseAndGoAway;
     if (encoder.Connection != decoder.Connection)
     {
         ThrowHelper.ThrowArgumentException_EncoderAndDecoderDonotShareTheSameConnObject();
     }
 }
Ejemplo n.º 10
0
        protected virtual void SetInitialChannelPipeline(IChannel ch)
        {
            var p = ch.Pipeline;
            IHttp2FrameWriter frameWriter = new DefaultHttp2FrameWriter();

            this.clientConnection.Remote.FlowController = new DefaultHttp2RemoteFlowController(this.clientConnection);
            this.clientConnection.Local.FlowController  = new DefaultHttp2LocalFlowController(this.clientConnection).FrameWriter(frameWriter);
            this.clientEncoder = new CompressorHttp2ConnectionEncoder(
                new DefaultHttp2ConnectionEncoder(this.clientConnection, frameWriter));

            IHttp2ConnectionDecoder decoder =
                new DefaultHttp2ConnectionDecoder(this.clientConnection, this.clientEncoder,
                                                  new DefaultHttp2FrameReader());

            this.clientHandler = new Http2ConnectionHandlerBuilder()
            {
                FrameListener = new DelegatingDecompressorFrameListener(this.clientConnection, this.clientListener.Object),
                // By default tests don't wait for server to gracefully shutdown streams
                GracefulShutdownTimeout = TimeSpan.Zero
            }
            .Codec(decoder, this.clientEncoder).Build();
            p.AddLast(this.clientHandler);
        }
        public CompressorHttp2ConnectionEncoder(IHttp2ConnectionEncoder encoder, int compressionLevel, int windowBits, int memLevel)
            : base(encoder)
        {
            if (compressionLevel < 0 || compressionLevel > 9)
            {
                ThrowHelper.ThrowArgumentException_InvalidCompressionLevel(compressionLevel);
            }
            if (windowBits < 9 || windowBits > 15)
            {
                ThrowHelper.ThrowArgumentException_InvalidWindowBits(windowBits);
            }
            if (memLevel < 1 || memLevel > 9)
            {
                ThrowHelper.ThrowArgumentException_InvalidMemLevel(memLevel);
            }
            _compressionLevel = compressionLevel;
            _windowBits       = windowBits;
            _memLevel         = memLevel;

            var connect = Connection;

            _propertyKey = connect.NewKey();
            connect.AddListener(new DelegatingConnectionAdapter(this));
        }
 public CompressorHttp2ConnectionEncoder(IHttp2ConnectionEncoder encoder)
     : this(encoder, DefaultCompressionLevel, DefaultWindowBits, DefaultMemLevel)
 {
 }
Ejemplo n.º 13
0
 public PrefaceUserEventHttp2ConnectionHandler(CountdownEvent latch, IHttp2ConnectionDecoder decoder, IHttp2ConnectionEncoder encoder, Http2Settings initialSettings)
     : base(decoder, encoder, initialSettings)
 {
     _latch = latch;
 }
Ejemplo n.º 14
0
 public HttpToHttp2ConnectionHandler(IHttp2ConnectionDecoder decoder, IHttp2ConnectionEncoder encoder,
                                     Http2Settings initialSettings, bool validateHeaders)
     : base(decoder, encoder, initialSettings)
 {
     _validateHeaders = validateHeaders;
 }
Ejemplo n.º 15
0
 public HelloWorldHttp2Handler(IHttp2ConnectionDecoder decoder, IHttp2ConnectionEncoder encoder, Http2Settings initialSettings)
     : base(decoder, encoder, initialSettings)
 {
 }
Ejemplo n.º 16
0
 public Http2ConnectionHandler(IHttp2ConnectionDecoder decoder, IHttp2ConnectionEncoder encoder, Http2Settings initialSettings)
     : this(decoder, encoder, initialSettings, false)
 {
 }
Ejemplo n.º 17
0
 /// <inheritdoc />
 protected override Http2MultiplexCodec Build(IHttp2ConnectionDecoder decoder, IHttp2ConnectionEncoder encoder, Http2Settings initialSettings)
 {
     return(new Http2MultiplexCodec(encoder, decoder, initialSettings, _childHandler, _upgradeStreamHandler, DecoupleCloseAndGoAway)
     {
         GracefulShutdownTimeout = GracefulShutdownTimeout
     });
 }
Ejemplo n.º 18
0
        protected override HelloWorldHttp2Handler Build(IHttp2ConnectionDecoder decoder, IHttp2ConnectionEncoder encoder, Http2Settings initialSettings)
        {
            HelloWorldHttp2Handler handler = new HelloWorldHttp2Handler(decoder, encoder, initialSettings);

            this.FrameListener = handler;
            return(handler);
        }
 protected override Http2ConnectionHandler Build(IHttp2ConnectionDecoder decoder, IHttp2ConnectionEncoder encoder, Http2Settings initialSettings)
 {
     return(new Http2ConnectionHandler(decoder, encoder, initialSettings, DecoupleCloseAndGoAway));
 }
 /// <summary>Create a new instance.</summary>
 /// <param name="connection">The <see cref="IHttp2Connection"/> associated with this decoder.</param>
 /// <param name="encoder">The <see cref="IHttp2ConnectionEncoder"/> associated with this decoder.</param>
 /// <param name="frameReader">Responsible for reading/parsing the raw frames. As opposed to this object which applies
 /// h2 semantics on top of the frames.</param>
 /// <param name="requestVerifier">Determines if push promised streams are valid.</param>
 /// <param name="autoAckSettings"><c>false</c> to disable automatically applying and sending settings acknowledge frame.
 /// The <paramref name="encoder"/> is expected to be an instance of
 /// <see cref="IHttp2SettingsReceivedConsumer"/> and will apply the earliest received but not yet
 /// ACKed SETTINGS when writing the SETTINGS ACKs. <c>true</c> to enable automatically
 /// applying and sending settings acknowledge frame.</param>
 public DefaultHttp2ConnectionDecoder(IHttp2Connection connection,
                                      IHttp2ConnectionEncoder encoder, IHttp2FrameReader frameReader, IHttp2PromisedRequestVerifier requestVerifier, bool autoAckSettings)
     : this(connection, encoder, frameReader, requestVerifier, autoAckSettings, true)
 {
 }
 /// <summary>Create a new instance.</summary>
 /// <param name="connection">The <see cref="IHttp2Connection"/> associated with this decoder.</param>
 /// <param name="encoder">The <see cref="IHttp2ConnectionEncoder"/> associated with this decoder.</param>
 /// <param name="frameReader">Responsible for reading/parsing the raw frames. As opposed to this object which applies
 /// h2 semantics on top of the frames.</param>
 /// <param name="requestVerifier">Determines if push promised streams are valid.</param>
 public DefaultHttp2ConnectionDecoder(IHttp2Connection connection,
                                      IHttp2ConnectionEncoder encoder, IHttp2FrameReader frameReader, IHttp2PromisedRequestVerifier requestVerifier)
     : this(connection, encoder, frameReader, requestVerifier, true, true)
 {
 }
 /// <summary>Create a new instance.</summary>
 /// <param name="connection">The <see cref="IHttp2Connection"/> associated with this decoder.</param>
 /// <param name="encoder">The <see cref="IHttp2ConnectionEncoder"/> associated with this decoder.</param>
 /// <param name="frameReader">Responsible for reading/parsing the raw frames. As opposed to this object which applies
 /// h2 semantics on top of the frames.</param>
 public DefaultHttp2ConnectionDecoder(IHttp2Connection connection,
                                      IHttp2ConnectionEncoder encoder, IHttp2FrameReader frameReader)
     : this(connection, encoder, frameReader, AlwaysVerifyPromisedRequestVerifier.Instance)
 {
 }
Ejemplo n.º 23
0
 public StreamBufferingEncoder(IHttp2ConnectionEncoder encoder)
     : this(encoder, Http2CodecUtil.SmallestMaxConcurrentStreams)
 {
 }