Exemplo n.º 1
0
    public TestInput(KestrelTrace log = null, ITimeoutControl timeoutControl = null)
    {
        _memoryPool = PinnedBlockMemoryPoolFactory.Create();
        var options = new PipeOptions(pool: _memoryPool, readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline, useSynchronizationContext: false);
        var pair    = DuplexPipe.CreateConnectionPair(options, options);

        Transport   = pair.Transport;
        Application = pair.Application;

        var connectionFeatures = new FeatureCollection();

        connectionFeatures.Set(Mock.Of <IConnectionLifetimeFeature>());

        Http1ConnectionContext = TestContextFactory.CreateHttpConnectionContext(
            serviceContext: new TestServiceContext
        {
            Log = log ?? new KestrelTrace(NullLoggerFactory.Instance)
        },
            connectionContext: Mock.Of <ConnectionContext>(),
            transport: Transport,
            timeoutControl: timeoutControl ?? Mock.Of <ITimeoutControl>(),
            memoryPool: _memoryPool,
            connectionFeatures: connectionFeatures);

        Http1Connection = new Http1Connection(Http1ConnectionContext);
        Http1Connection.HttpResponseControl = Mock.Of <IHttpResponseControl>();
        Http1Connection.Reset();
    }
Exemplo n.º 2
0
        public Http2FrameWriter(
            PipeWriter outputPipeWriter,
            BaseConnectionContext connectionContext,
            Http2Connection http2Connection,
            OutputFlowControl connectionOutputFlowControl,
            ITimeoutControl timeoutControl,
            MinDataRate?minResponseDataRate,
            string connectionId,
            MemoryPool <byte> memoryPool,
            ServiceContext serviceContext)
        {
            // Allow appending more data to the PipeWriter when a flush is pending.
            _outputWriter                = new ConcurrentPipeWriter(outputPipeWriter, memoryPool, _writeLock);
            _connectionContext           = connectionContext;
            _http2Connection             = http2Connection;
            _connectionOutputFlowControl = connectionOutputFlowControl;
            _connectionId                = connectionId;
            _log                 = serviceContext.Log;
            _timeoutControl      = timeoutControl;
            _minResponseDataRate = minResponseDataRate;
            _flusher             = new TimingPipeFlusher(timeoutControl, serviceContext.Log);
            _flusher.Initialize(_outputWriter);
            _outgoingFrame        = new Http2Frame();
            _headerEncodingBuffer = new byte[_maxFrameSize];

            _scheduleInline = serviceContext.Scheduler == PipeScheduler.Inline;

            _hpackEncoder = new DynamicHPackEncoder(serviceContext.ServerOptions.AllowResponseHeaderCompression);
        }
Exemplo n.º 3
0
    public static HttpMultiplexedConnectionContext CreateHttp3ConnectionContext(
        MultiplexedConnectionContext connectionContext = null,
        ServiceContext serviceContext         = null,
        IFeatureCollection connectionFeatures = null,
        MemoryPool <byte> memoryPool          = null,
        IPEndPoint localEndPoint       = null,
        IPEndPoint remoteEndPoint      = null,
        ITimeoutControl timeoutControl = null)
    {
        var http3ConnectionContext = new HttpMultiplexedConnectionContext(
            "TEST",
            HttpProtocols.Http3,
            altSvcHeader: null,
            connectionContext ?? new TestMultiplexedConnectionContext {
            ConnectionId = "TEST"
        },
            serviceContext ?? CreateServiceContext(new KestrelServerOptions()),
            connectionFeatures ?? new FeatureCollection(),
            memoryPool ?? PinnedBlockMemoryPoolFactory.Create(),
            localEndPoint,
            remoteEndPoint)
        {
            TimeoutControl = timeoutControl
        };

        return(http3ConnectionContext);
    }
 public StreamSafePipeFlusher(
     PipeWriter writer,
     ITimeoutControl timeoutControl)
 {
     _writer         = writer;
     _timeoutControl = timeoutControl;
 }
Exemplo n.º 5
0
        public static HttpConnectionContext CreateHttpConnectionContext(
            ConnectionContext connectionContext,
            ServiceContext serviceContext,
            IDuplexPipe transport,
            IFeatureCollection connectionFeatures,
            MemoryPool <byte> memoryPool   = null,
            IPEndPoint localEndPoint       = null,
            IPEndPoint remoteEndPoint      = null,
            ITimeoutControl timeoutControl = null)
        {
            var context = new HttpConnectionContext(
                "TestConnectionId",
                HttpProtocols.Http1,
                connectionContext,
                serviceContext,
                connectionFeatures,
                memoryPool ?? MemoryPool <byte> .Shared,
                localEndPoint,
                remoteEndPoint,
                transport);

            context.TimeoutControl = timeoutControl;

            return(context);
        }
Exemplo n.º 6
0
        public static Http3StreamContext CreateHttp3StreamContext(
            string connectionId = null,
            ConnectionContext connectionContext   = null,
            ServiceContext serviceContext         = null,
            IFeatureCollection connectionFeatures = null,
            MemoryPool <byte> memoryPool          = null,
            IPEndPoint localEndPoint       = null,
            IPEndPoint remoteEndPoint      = null,
            IDuplexPipe transport          = null,
            ITimeoutControl timeoutControl = null,
            IHttp3StreamLifetimeHandler streamLifetimeHandler = null)
        {
            var context = new Http3StreamContext
                          (
                connectionId: connectionId ?? "TestConnectionId",
                protocols: HttpProtocols.Http3,
                connectionContext: connectionContext,
                serviceContext: serviceContext ?? CreateServiceContext(new KestrelServerOptions()),
                connectionFeatures: connectionFeatures ?? new FeatureCollection(),
                memoryPool: memoryPool ?? MemoryPool <byte> .Shared,
                localEndPoint: localEndPoint,
                remoteEndPoint: remoteEndPoint,
                transport: transport,
                streamLifetimeHandler: streamLifetimeHandler,
                streamContext: null,
                settings: null
                          );

            context.TimeoutControl = timeoutControl;

            return(context);
        }
 public TimingPipeFlusher(
     PipeWriter writer,
     ITimeoutControl timeoutControl)
 {
     _writer         = writer;
     _timeoutControl = timeoutControl;
 }
Exemplo n.º 8
0
 public TimingPipeFlusher(
     PipeWriter writer,
     ITimeoutControl timeoutControl,
     IKestrelTrace log)
 {
     _writer         = writer;
     _timeoutControl = timeoutControl;
     _log            = log;
 }
        public Http2FrameWriter(
            PipeWriter outputPipeWriter,
            PipeReader outputPipeReader,
            Http2OutputFlowControl connectionOutputFlowControl,
            ITimeoutControl timeoutControl)
        {
            _outputWriter = outputPipeWriter;
            _outputReader = outputPipeReader;

            _connectionOutputFlowControl = connectionOutputFlowControl;
            _flusher = new StreamSafePipeFlusher(_outputWriter, timeoutControl);
        }
        //private int _unflushedBytes;

        public Http3FrameWriter(PipeWriter output, ConnectionContext connectionContext, ITimeoutControl timeoutControl, MinDataRate minResponseDataRate, string connectionId, MemoryPool <byte> memoryPool, IKestrelTrace log)
        {
            _outputWriter        = output;
            _connectionContext   = connectionContext;
            _timeoutControl      = timeoutControl;
            _minResponseDataRate = minResponseDataRate;
            _memoryPool          = memoryPool;
            _log                  = log;
            _outgoingFrame        = new Http3RawFrame();
            _flusher              = new TimingPipeFlusher(_outputWriter, timeoutControl, log);
            _headerEncodingBuffer = new byte[_maxFrameSize];
        }
Exemplo n.º 11
0
 public OutputProducer(
     IPipe pipe,
     string connectionId,
     IKestrelTrace log,
     ITimeoutControl timeoutControl)
 {
     _pipe           = pipe;
     _connectionId   = connectionId;
     _timeoutControl = timeoutControl;
     _log            = log;
     _flushCompleted = OnFlushCompleted;
 }
Exemplo n.º 12
0
    public static void StartDrainTimeout(this ITimeoutControl timeoutControl, MinDataRate?minDataRate, long?maxResponseBufferSize)
    {
        // If maxResponseBufferSize has no value, there's no backpressure and we can't reasonably time out draining.
        if (minDataRate == null || maxResponseBufferSize == null)
        {
            return;
        }

        // Ensure we have at least the grace period from this point to finish draining the response.
        timeoutControl.BytesWrittenToBuffer(minDataRate, 1);
        timeoutControl.StartTimingWrite();
    }
Exemplo n.º 13
0
 public Http2OutputProducer(
     int streamId,
     Http2FrameWriter frameWriter,
     StreamOutputFlowControl flowControl,
     ITimeoutControl timeoutControl,
     MemoryPool <byte> pool)
 {
     _streamId                = streamId;
     _frameWriter             = frameWriter;
     _flowControl             = flowControl;
     _dataPipe                = CreateDataPipe(pool);
     _flusher                 = new StreamSafePipeFlusher(_dataPipe.Writer, timeoutControl);
     _dataWriteProcessingTask = ProcessDataWrites();
 }
Exemplo n.º 14
0
 public Http1OutputProducer(
     PipeReader outputPipeReader,
     PipeWriter pipeWriter,
     string connectionId,
     IKestrelTrace log,
     ITimeoutControl timeoutControl)
 {
     _outputPipeReader = outputPipeReader;
     _pipeWriter       = pipeWriter;
     _connectionId     = connectionId;
     _timeoutControl   = timeoutControl;
     _log            = log;
     _flushCompleted = OnFlushCompleted;
 }
 public Http2FrameWriter(
     PipeWriter outputPipeWriter,
     ConnectionContext connectionContext,
     OutputFlowControl connectionOutputFlowControl,
     ITimeoutControl timeoutControl,
     string connectionId,
     IKestrelTrace log)
 {
     _outputWriter                = outputPipeWriter;
     _connectionContext           = connectionContext;
     _connectionOutputFlowControl = connectionOutputFlowControl;
     _connectionId                = connectionId;
     _log     = log;
     _flusher = new StreamSafePipeFlusher(_outputWriter, timeoutControl);
 }
Exemplo n.º 16
0
 public Http1OutputProducer(
     PipeWriter pipeWriter,
     string connectionId,
     ConnectionContext connectionContext,
     IKestrelTrace log,
     ITimeoutControl timeoutControl,
     IHttpMinResponseDataRateFeature minResponseDataRateFeature)
 {
     _pipeWriter        = pipeWriter;
     _connectionId      = connectionId;
     _connectionContext = connectionContext;
     _log = log;
     _minResponseDataRateFeature = minResponseDataRateFeature;
     _flusher = new TimingPipeFlusher(pipeWriter, timeoutControl, log);
 }
Exemplo n.º 17
0
 public Http1OutputProducer(
     PipeWriter pipeWriter,
     string connectionId,
     ConnectionContext connectionContext,
     IKestrelTrace log,
     ITimeoutControl timeoutControl,
     IBytesWrittenFeature transportBytesWrittenFeature)
 {
     _pipeWriter        = pipeWriter;
     _connectionId      = connectionId;
     _connectionContext = connectionContext;
     _timeoutControl    = timeoutControl;
     _log = log;
     _transportBytesWrittenFeature = transportBytesWrittenFeature;
     _flusher = new StreamSafePipeFlusher(pipeWriter, timeoutControl);
 }
Exemplo n.º 18
0
        public static void StartDrainTimeout(this ITimeoutControl timeoutControl, MinDataRate minDataRate, long?maxResponseBufferSize)
        {
            // If maxResponseBufferSize has no value, there's no backpressure and we can't reasonably timeout draining.
            if (minDataRate == null || maxResponseBufferSize == null)
            {
                return;
            }

            // With full backpressure and a connection adapter there could be 2 two pipes buffering.
            // We already validate that the buffer size is positive.
            // There's no reason to stop timing the write after the connection is closed.
            var oneBufferSize    = maxResponseBufferSize.Value;
            var maxBufferedBytes = oneBufferSize < long.MaxValue / 2 ? oneBufferSize * 2 : long.MaxValue;

            timeoutControl.StartTimingWrite(minDataRate, maxBufferedBytes);
        }
Exemplo n.º 19
0
 public Http2FrameWriter(
     PipeWriter outputPipeWriter,
     ConnectionContext connectionContext,
     OutputFlowControl connectionOutputFlowControl,
     ITimeoutControl timeoutControl,
     string connectionId,
     IKestrelTrace log)
 {
     _outputWriter                = outputPipeWriter;
     _connectionContext           = connectionContext;
     _connectionOutputFlowControl = connectionOutputFlowControl;
     _connectionId                = connectionId;
     _log                  = log;
     _flusher              = new TimingPipeFlusher(_outputWriter, timeoutControl);
     _outgoingFrame        = new Http2Frame();
     _headerEncodingBuffer = new byte[_maxFrameSize];
 }
Exemplo n.º 20
0
 public Proto2OutputProducer(
     int streamId,
     Proto2FrameWriter frameWriter,
     StreamOutputFlowControl flowControl,
     ITimeoutControl timeoutControl,
     MemoryPool <byte> pool,
     Proto2Stream stream,
     IKestrelTrace log)
 {
     _streamId                = streamId;
     _frameWriter             = frameWriter;
     _flowControl             = flowControl;
     _stream                  = stream;
     _dataPipe                = CreateDataPipe(pool);
     _flusher                 = new TimingPipeFlusher(_dataPipe.Writer, timeoutControl, log);
     _dataWriteProcessingTask = ProcessDataWrites();
 }
Exemplo n.º 21
0
 public Proto1OutputProducer(
     PipeWriter pipeWriter,
     string connectionId,
     ConnectionContext connectionContext,
     IKestrelTrace log,
     ITimeoutControl timeoutControl,
     IProtoMinResponseDataRateFeature minResponseDataRateFeature,
     MemoryPool <byte> memoryPool)
 {
     _pipeWriter        = pipeWriter;
     _connectionId      = connectionId;
     _connectionContext = connectionContext;
     _log = log;
     _minResponseDataRateFeature = minResponseDataRateFeature;
     _flusher    = new TimingPipeFlusher(pipeWriter, timeoutControl, log);
     _memoryPool = memoryPool;
 }
Exemplo n.º 22
0
    public static Http3StreamContext CreateHttp3StreamContext(
        string connectionId = null,
        BaseConnectionContext connectionContext = null,
        ServiceContext serviceContext           = null,
        IFeatureCollection connectionFeatures   = null,
        MemoryPool <byte> memoryPool            = null,
        IPEndPoint localEndPoint       = null,
        IPEndPoint remoteEndPoint      = null,
        IDuplexPipe transport          = null,
        ITimeoutControl timeoutControl = null,
        IHttp3StreamLifetimeHandler streamLifetimeHandler = null)
    {
        var http3ConnectionContext = CreateHttp3ConnectionContext(
            null,
            serviceContext,
            connectionFeatures,
            memoryPool,
            localEndPoint,
            remoteEndPoint,
            timeoutControl);

        var http3Conection = new Http3Connection(http3ConnectionContext)
        {
            _streamLifetimeHandler = streamLifetimeHandler
        };

        return(new Http3StreamContext
               (
                   connectionId: connectionId ?? "TestConnectionId",
                   protocols: HttpProtocols.Http3,
                   altSvcHeader: null,
                   connectionContext: connectionContext,
                   serviceContext: serviceContext ?? CreateServiceContext(new KestrelServerOptions()),
                   connectionFeatures: connectionFeatures ?? new FeatureCollection(),
                   memoryPool: memoryPool ?? MemoryPool <byte> .Shared,
                   localEndPoint: localEndPoint,
                   remoteEndPoint: remoteEndPoint,
                   streamContext: new DefaultConnectionContext(),
                   connection: http3Conection
               )
        {
            TimeoutControl = timeoutControl,
            Transport = transport,
        });
    }
Exemplo n.º 23
0
 public Http1OutputProducer(
     PipeReader outputPipeReader,
     PipeWriter pipeWriter,
     string connectionId,
     IKestrelTrace log,
     ITimeoutControl timeoutControl,
     IConnectionLifetimeFeature lifetimeFeature,
     IBytesWrittenFeature transportBytesWrittenFeature)
 {
     _outputPipeReader = outputPipeReader;
     _pipeWriter       = pipeWriter;
     _connectionId     = connectionId;
     _timeoutControl   = timeoutControl;
     _log             = log;
     _flushCompleted  = OnFlushCompleted;
     _lifetimeFeature = lifetimeFeature;
     _transportBytesWrittenFeature = transportBytesWrittenFeature;
 }
Exemplo n.º 24
0
 public Http1OutputProducer(
     PipeWriter pipeWriter,
     string connectionId,
     ConnectionContext connectionContext,
     IKestrelTrace log,
     ITimeoutControl timeoutControl,
     IHttpMinResponseDataRateFeature minResponseDataRateFeature,
     MemoryPool <byte> memoryPool)
 {
     // Allow appending more data to the PipeWriter when a flush is pending.
     _pipeWriter        = new ConcurrentPipeWriter(pipeWriter, memoryPool, _contextLock);
     _connectionId      = connectionId;
     _connectionContext = connectionContext;
     _log = log;
     _minResponseDataRateFeature = minResponseDataRateFeature;
     _flusher    = new TimingPipeFlusher(_pipeWriter, timeoutControl, log);
     _memoryPool = memoryPool;
 }
Exemplo n.º 25
0
 public Http2FrameWriter(
     PipeWriter outputPipeWriter,
     ConnectionContext connectionContext,
     Http2Connection http2Connection,
     OutputFlowControl connectionOutputFlowControl,
     ITimeoutControl timeoutControl,
     MinDataRate minResponseDataRate,
     string connectionId,
     IKestrelTrace log)
 {
     _outputWriter                = outputPipeWriter;
     _connectionContext           = connectionContext;
     _http2Connection             = http2Connection;
     _connectionOutputFlowControl = connectionOutputFlowControl;
     _connectionId                = connectionId;
     _log                  = log;
     _timeoutControl       = timeoutControl;
     _minResponseDataRate  = minResponseDataRate;
     _flusher              = new TimingPipeFlusher(_outputWriter, timeoutControl, log);
     _outgoingFrame        = new Http2Frame();
     _headerEncodingBuffer = new byte[_maxFrameSize];
 }
Exemplo n.º 26
0
        public static Http2StreamContext CreateHttp2StreamContext(
            string connectionId                   = null,
            ServiceContext serviceContext         = null,
            IFeatureCollection connectionFeatures = null,
            MemoryPool <byte> memoryPool          = null,
            IPEndPoint localEndPoint              = null,
            IPEndPoint remoteEndPoint             = null,
            int?streamId = null,
            IHttp2StreamLifetimeHandler streamLifetimeHandler = null,
            Http2PeerSettings clientPeerSettings          = null,
            Http2PeerSettings serverPeerSettings          = null,
            Http2FrameWriter frameWriter                  = null,
            InputFlowControl connectionInputFlowControl   = null,
            OutputFlowControl connectionOutputFlowControl = null,
            ITimeoutControl timeoutControl                = null)
        {
            var context = new Http2StreamContext
                          (
                connectionId: connectionId ?? "TestConnectionId",
                protocols: HttpProtocols.Http2,
                altSvcHeader: null,
                serviceContext: serviceContext ?? CreateServiceContext(new KestrelServerOptions()),
                connectionFeatures: connectionFeatures ?? new FeatureCollection(),
                memoryPool: memoryPool ?? MemoryPool <byte> .Shared,
                localEndPoint: localEndPoint,
                remoteEndPoint: remoteEndPoint,
                streamId: streamId ?? 0,
                streamLifetimeHandler: streamLifetimeHandler,
                clientPeerSettings: clientPeerSettings ?? new Http2PeerSettings(),
                serverPeerSettings: serverPeerSettings ?? new Http2PeerSettings(),
                frameWriter: frameWriter,
                connectionInputFlowControl: connectionInputFlowControl,
                connectionOutputFlowControl: connectionOutputFlowControl
                          );

            context.TimeoutControl = timeoutControl;

            return(context);
        }
Exemplo n.º 27
0
        public static HttpMultiplexedConnectionContext CreateHttp3ConnectionContext(
            MultiplexedConnectionContext connectionContext = null,
            ServiceContext serviceContext         = null,
            IFeatureCollection connectionFeatures = null,
            MemoryPool <byte> memoryPool          = null,
            IPEndPoint localEndPoint       = null,
            IPEndPoint remoteEndPoint      = null,
            ITimeoutControl timeoutControl = null)
        {
            var http3ConnectionContext = new HttpMultiplexedConnectionContext(
                "TestConnectionId",
                connectionContext ?? new TestMultiplexedConnectionContext(),
                serviceContext ?? CreateServiceContext(new KestrelServerOptions()),
                connectionFeatures ?? new FeatureCollection(),
                memoryPool ?? PinnedBlockMemoryPoolFactory.Create(),
                localEndPoint,
                remoteEndPoint);

            http3ConnectionContext.TimeoutControl = timeoutControl;

            return(http3ConnectionContext);
        }
Exemplo n.º 28
0
        //private int _unflushedBytes;

        public Http3FrameWriter(PipeWriter output, ConnectionContext connectionContext, ITimeoutControl timeoutControl, MinDataRate?minResponseDataRate, string connectionId, MemoryPool <byte> memoryPool, IKestrelTrace log, IStreamIdFeature streamIdFeature, Http3PeerSettings clientPeerSettings, IHttp3Stream http3Stream)
        {
            _outputWriter        = output;
            _connectionContext   = connectionContext;
            _timeoutControl      = timeoutControl;
            _minResponseDataRate = minResponseDataRate;
            _connectionId        = connectionId;
            _memoryPool          = memoryPool;
            _log                  = log;
            _streamIdFeature      = streamIdFeature;
            _http3Stream          = http3Stream;
            _outgoingFrame        = new Http3RawFrame();
            _flusher              = new TimingPipeFlusher(_outputWriter, timeoutControl, log);
            _headerEncodingBuffer = new byte[_maxFrameSize];

            // Note that max total header size value doesn't react to settings change during a stream.
            // Unlikely to be a problem in practice:
            // - Settings rarely change after the start of a connection.
            // - Response header size limits are a best-effort requirement in the spec.
            _maxTotalHeaderSize = clientPeerSettings.MaxRequestHeaderFieldSectionSize > int.MaxValue
                ? int.MaxValue
                : (int)clientPeerSettings.MaxRequestHeaderFieldSectionSize;
        }
Exemplo n.º 29
0
 public Http2FrameWriter(
     PipeWriter outputPipeWriter,
     ConnectionContext connectionContext,
     Http2Connection http2Connection,
     OutputFlowControl connectionOutputFlowControl,
     ITimeoutControl timeoutControl,
     MinDataRate minResponseDataRate,
     string connectionId,
     MemoryPool <byte> memoryPool,
     IKestrelTrace log)
 {
     // Allow appending more data to the PipeWriter when a flush is pending.
     _outputWriter                = new ConcurrentPipeWriter(outputPipeWriter, memoryPool, _writeLock);
     _connectionContext           = connectionContext;
     _http2Connection             = http2Connection;
     _connectionOutputFlowControl = connectionOutputFlowControl;
     _connectionId                = connectionId;
     _log                  = log;
     _timeoutControl       = timeoutControl;
     _minResponseDataRate  = minResponseDataRate;
     _flusher              = new TimingPipeFlusher(_outputWriter, timeoutControl, log);
     _outgoingFrame        = new Http2Frame();
     _headerEncodingBuffer = new byte[_maxFrameSize];
 }
Exemplo n.º 30
0
 public TestHttpOutputProducer(Pipe pipe, string connectionId, ConnectionContext connectionContext, IKestrelTrace log, ITimeoutControl timeoutControl, IHttpMinResponseDataRateFeature minResponseDataRateFeature) : base(pipe.Writer, connectionId, connectionContext, log, timeoutControl, minResponseDataRateFeature)
 {
     Pipe = pipe;
 }