Пример #1
0
        internal async ValueTask <Dictionary <long, long> > ExpectSettingsAsync()
        {
            var http3WithPayload = await ReceiveFrameAsync();

            Http3InMemory.AssertFrameType(http3WithPayload.Type, Http3FrameType.Settings);

            var payload = http3WithPayload.PayloadSequence;

            var settings = new Dictionary <long, long>();

            while (true)
            {
                var id = VariableLengthIntegerHelper.GetInteger(payload, out var consumed, out _);
                if (id == -1)
                {
                    break;
                }

                payload = payload.Slice(consumed);

                var value = VariableLengthIntegerHelper.GetInteger(payload, out consumed, out _);
                if (value == -1)
                {
                    break;
                }

                payload = payload.Slice(consumed);
                settings.Add(id, value);
            }

            return(settings);
        }
Пример #2
0
 public TestMultiplexedConnectionContext(Http3InMemory testBase)
 {
     _testBase = testBase;
     Features  = new FeatureCollection();
     Features.Set <IConnectionLifetimeNotificationFeature>(this);
     Features.Set <IConnectionHeartbeatFeature>(this);
     Features.Set <IProtocolErrorCodeFeature>(this);
     ConnectionClosedRequested = ConnectionClosingCts.Token;
 }
Пример #3
0
 public Http3RequestStream(Http3InMemory testBase, Http3Connection connection, TestStreamContext testStreamContext, Http3RequestHeaderHandler headerHandler)
     : base(testStreamContext)
 {
     TestBase            = testBase;
     Connection          = connection;
     _streamId           = testStreamContext.StreamId;
     _testStreamContext  = testStreamContext;
     this._headerHandler = headerHandler;
 }
Пример #4
0
    public override void Initialize(TestContext context, MethodInfo methodInfo, object[] testMethodArguments, ITestOutputHelper testOutputHelper)
    {
        base.Initialize(context, methodInfo, testMethodArguments, testOutputHelper);

        _serviceContext = new TestServiceContext(LoggerFactory)
        {
            Scheduler = PipeScheduler.Inline,
        };

        Http3Api = new Http3InMemory(_serviceContext, _serviceContext.MockSystemClock, _mockTimeoutHandler.Object, LoggerFactory);
    }
Пример #5
0
        internal async ValueTask <Dictionary <string, string> > ExpectHeadersAsync(bool expectEnd = false)
        {
            var http3WithPayload = await ReceiveFrameAsync(expectEnd);

            Http3InMemory.AssertFrameType(http3WithPayload.Type, Http3FrameType.Headers);

            _headerHandler.DecodedHeaders.Clear();
            _headerHandler.QpackDecoder.Decode(http3WithPayload.PayloadSequence, this);
            _headerHandler.QpackDecoder.Reset();
            return(_headerHandler.DecodedHeaders.ToDictionary(kvp => kvp.Key, kvp => kvp.Value, _headerHandler.DecodedHeaders.Comparer));
        }
    public static async ValueTask <WebTransportSession> GenerateSession(Http3InMemory inMemory, TaskCompletionSource exitSessionTcs)
    {
        var appCompletedTcs = new TaskCompletionSource <IWebTransportSession>(TaskCreationOptions.RunContinuationsAsynchronously);

        await inMemory.InitializeConnectionAsync(async context =>
        {
            var webTransportFeature = context.Features.GetRequiredFeature <IHttpWebTransportFeature>();

#pragma warning disable CA2252 // This API requires opting into preview features
            try
            {
                var session = await webTransportFeature.AcceptAsync(CancellationToken.None).DefaultTimeout();
                appCompletedTcs.SetResult(session);
            }
            catch (TimeoutException exception)
            {
                appCompletedTcs.SetException(exception);
            }
#pragma warning restore CA2252

            // wait for the test to tell us to kill the application
            await exitSessionTcs.Task;
        });

        var controlStream = await inMemory.CreateControlStream();

        var controlStream2 = await inMemory.GetInboundControlStream();

        var settings = new Http3PeerSettings()
        {
            EnableWebTransport = 1,
            H3Datagram         = 1,
        };

        await controlStream.SendSettingsAsync(settings.GetNonProtocolDefaults());

        var response1 = await controlStream2.ExpectSettingsAsync();

        await inMemory.ServerReceivedSettingsReader.ReadAsync().DefaultTimeout();

        var requestStream = await inMemory.CreateRequestStream(new[]
        {
            new KeyValuePair <string, string>(InternalHeaderNames.Method, "CONNECT"),
            new KeyValuePair <string, string>(InternalHeaderNames.Protocol, "webtransport"),
            new KeyValuePair <string, string>(InternalHeaderNames.Scheme, "http"),
            new KeyValuePair <string, string>(InternalHeaderNames.Path, "/"),
            new KeyValuePair <string, string>(InternalHeaderNames.Authority, "server.example.com"),
            new KeyValuePair <string, string>(HeaderNames.Origin, "server.example.com"),
            new KeyValuePair <string, string>(WebTransportSession.CurrentSuppportedVersion, "1")
        });

        return((WebTransportSession)await appCompletedTcs.Task);
    }
Пример #7
0
        internal void VerifyGoAway(Http3FrameWithPayload frame, long expectedLastStreamId)
        {
            Http3InMemory.AssertFrameType(frame.Type, Http3FrameType.GoAway);
            var payload = frame.Payload;

            if (!VariableLengthIntegerHelper.TryRead(payload.Span, out var streamId, out var _))
            {
                throw new InvalidOperationException("Failed to read GO_AWAY stream ID.");
            }
            if (streamId != expectedLastStreamId)
            {
                throw new InvalidOperationException($"Expected stream ID {expectedLastStreamId}, got {streamId}.");
            }
        }
Пример #8
0
 public Http3ControlStream(Http3InMemory testBase, TestStreamContext testStreamContext)
     : base(testStreamContext)
 {
     TestBase  = testBase;
     _streamId = testStreamContext.StreamId;
 }
Пример #9
0
 public TimeoutControlConnectionInvoker(Http3InMemory http3, ITimeoutHandler inner)
 {
     _http3 = http3;
     _inner = inner;
 }
Пример #10
0
 public LifetimeHandlerInterceptor(IHttp3StreamLifetimeHandler inner, Http3InMemory http3TestBase)
 {
     _inner         = inner;
     _http3TestBase = http3TestBase;
 }