Exemplo n.º 1
0
        protected async Task <Http2Frame> ExpectAsync(Http2FrameType type, int withLength, byte withFlags, int withStreamId)
        {
            var frame = await ReceiveFrameAsync((uint)withLength);

            Assert.Equal(type, frame.Type);
            Assert.Equal(withLength, frame.PayloadLength);
            Assert.Equal(withFlags, frame.Flags);
            Assert.Equal(withStreamId, frame.StreamId);

            return(frame);
        }
Exemplo n.º 2
0
 public Http2FrameHeader(
     int length,
     Http2FrameType type,
     byte flags,
     int streamID)
 {
     this.Length   = length;
     this.Type     = type;
     this.Flags    = flags;
     this.R        = false;
     this.StreamID = streamID;
 }
Exemplo n.º 3
0
        public async Task AbortedStream_ResetsAndDrainsRequest_RefusesFramesAfterCooldownExpires(Http2FrameType finalFrameType)
        {
            var mockSystemClock = _serviceContext.MockSystemClock;

            var headers = new[]
            {
                new KeyValuePair <string, string>(HeaderNames.Method, "POST"),
                new KeyValuePair <string, string>(HeaderNames.Path, "/"),
                new KeyValuePair <string, string>(HeaderNames.Scheme, "http"),
            };

            await InitializeConnectionAsync(_appAbort);

            await StartStreamAsync(1, headers, endStream : false);

            await WaitForStreamErrorAsync(1, Http2ErrorCode.INTERNAL_ERROR, "The connection was aborted by the application.");

            // There's a race when the appfunc is exiting about how soon it unregisters the stream.
            for (var i = 0; i < 10; i++)
            {
                await SendDataAsync(1, new byte[100], endStream : false);
            }

            // Just short of the timeout
            mockSystemClock.UtcNow += Constants.RequestBodyDrainTimeout;
            (_connection as IRequestProcessor).Tick(mockSystemClock.UtcNow);

            // Still fine
            await SendDataAsync(1, new byte[100], endStream : false);

            // Just past the timeout
            mockSystemClock.UtcNow += TimeSpan.FromTicks(1);
            (_connection as IRequestProcessor).Tick(mockSystemClock.UtcNow);

            // Send an extra frame to make it fail
            switch (finalFrameType)
            {
            case Http2FrameType.DATA:
                await SendDataAsync(1, new byte[100], endStream : true);

                break;

            case Http2FrameType.HEADERS:
                await SendHeadersAsync(1, Http2HeadersFrameFlags.END_STREAM | Http2HeadersFrameFlags.END_HEADERS, _requestTrailers);

                break;

            default:
                throw new NotImplementedException(finalFrameType.ToString());
            }

            await WaitForConnectionErrorAsync <Http2ConnectionErrorException>(ignoreNonGoAwayFrames : false, expectedLastStreamId : 1, Http2ErrorCode.STREAM_CLOSED,
                                                                              CoreStrings.FormatHttp2ErrorStreamClosed(finalFrameType, 1));
        }
Exemplo n.º 4
0
 public static partial void Http2FrameSending(ILogger logger, string connectionId, Http2FrameType type, int id, int length, object flags);
Exemplo n.º 5
0
 private static partial void Http2FrameReceived(ILogger logger, string connectionId, Http2FrameType type, int id, int length, object flags);
Exemplo n.º 6
0
        public async Task AbortedStream_ResetsAndDrainsRequest_RefusesFramesAfterCooldownExpires(Http2FrameType finalFrameType)
        {
            var mockSystemClock = _serviceContext.MockSystemClock;

            var headers = new[]
            {
                new KeyValuePair <string, string>(HeaderNames.Method, "POST"),
                new KeyValuePair <string, string>(HeaderNames.Path, "/"),
                new KeyValuePair <string, string>(HeaderNames.Scheme, "http"),
            };

            await InitializeConnectionAsync(_appAbort);

            await StartStreamAsync(1, headers, endStream : false);

            await WaitForStreamErrorAsync(1, Http2ErrorCode.INTERNAL_ERROR, "The connection was aborted by the application.");

            var cts = new CancellationTokenSource();

            async Task AdvanceClockAndSendFrames()
            {
                if (finalFrameType == Http2FrameType.CONTINUATION)
                {
                    await SendHeadersAsync(1, Http2HeadersFrameFlags.END_STREAM, new byte[0]);
                }

                // There's a race when the appfunc is exiting about how soon it unregisters the stream, so retry until success.
                while (!cts.Token.IsCancellationRequested)
                {
                    // Just past the timeout
                    mockSystemClock.UtcNow += Constants.RequestBodyDrainTimeout + TimeSpan.FromTicks(1);
                    (_connection as IRequestProcessor).Tick(mockSystemClock.UtcNow);

                    // Send an extra frame to make it fail
                    switch (finalFrameType)
                    {
                    case Http2FrameType.DATA:
                        await SendDataAsync(1, new byte[100], endStream : false);

                        break;

                    case Http2FrameType.CONTINUATION:
                        await SendContinuationAsync(1, Http2ContinuationFrameFlags.NONE, new byte[0]);

                        break;

                    default:
                        throw new NotImplementedException(finalFrameType.ToString());
                    }

                    if (!cts.Token.IsCancellationRequested)
                    {
                        await Task.Delay(10);
                    }
                }
            }

            var sendTask = AdvanceClockAndSendFrames();

            await WaitForConnectionErrorAsync <Http2ConnectionErrorException>(
                ignoreNonGoAwayFrames : false,
                expectedLastStreamId : 1,
                Http2ErrorCode.STREAM_CLOSED,
                CoreStrings.FormatHttp2ErrorStreamClosed(finalFrameType, 1));

            cts.Cancel();

            await sendTask.DefaultTimeout();
        }
Exemplo n.º 7
0
 internal static string FormatHttp2ErrorStreamAborted(Http2FrameType frameType, int streamId) => $"A frame of type {frameType} was received after stream {streamId} was reset or aborted.";
Exemplo n.º 8
0
 internal static string FormatHttp2ErrorStreamIdle(Http2FrameType frameType, int streamId) => $"The client sent a {frameType} frame to idle stream ID {streamId}.";
Exemplo n.º 9
0
 internal static string FormatHttp2ErrorUnexpectedFrameLength(Http2FrameType frameType, int expectedLength) => $"The client sent a {frameType} frame with length different than {expectedLength}.";
Exemplo n.º 10
0
 internal static string FormatHttp2ErrorStreamSelfDependency(Http2FrameType frameType, int streamId) => $"The client sent a {frameType} frame with dependency information that would cause stream ID {streamId} to depend on itself.";
Exemplo n.º 11
0
 internal static string FormatHttp2ErrorStreamHalfClosedRemote(Http2FrameType frameType, int streamId) => $"The client sent a {frameType} frame to stream ID {streamId} which is in the \"half-closed(remote) state\".";
Exemplo n.º 12
0
 internal static string FormatHttp2ErrorPaddingTooLong(Http2FrameType frameType) => $"The client sent a {frameType} frame with padding longer than or with the same length as the sent data.";
Exemplo n.º 13
0
 internal static string FormatHttp2ErrorStreamIdNotZero(Http2FrameType frameType) => $"The client sent a {frameType} frame with stream ID different than 0.";
Exemplo n.º 14
0
 internal static string FormatHttp2ErrorHeadersInterleaved(Http2FrameType frameType, int streamId, int headersStreamId) => $"The client sent a {frameType} frame to stream ID {streamId} before signaling of the header block for stream ID {headersStreamId}.";
Exemplo n.º 15
0
 internal static string FormatHttp2ErrorStreamIdEven(Http2FrameType frameType, int streamId) => $"The client sent a {frameType} frame with even stream ID {streamId}.";