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); }
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; }
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)); }
public static partial void Http2FrameSending(ILogger logger, string connectionId, Http2FrameType type, int id, int length, object flags);
private static partial void Http2FrameReceived(ILogger logger, string connectionId, Http2FrameType type, int id, int length, object flags);
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(); }
internal static string FormatHttp2ErrorStreamAborted(Http2FrameType frameType, int streamId) => $"A frame of type {frameType} was received after stream {streamId} was reset or aborted.";
internal static string FormatHttp2ErrorStreamIdle(Http2FrameType frameType, int streamId) => $"The client sent a {frameType} frame to idle stream ID {streamId}.";
internal static string FormatHttp2ErrorUnexpectedFrameLength(Http2FrameType frameType, int expectedLength) => $"The client sent a {frameType} frame with length different than {expectedLength}.";
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.";
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\".";
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.";
internal static string FormatHttp2ErrorStreamIdNotZero(Http2FrameType frameType) => $"The client sent a {frameType} frame with stream ID different than 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}.";
internal static string FormatHttp2ErrorStreamIdEven(Http2FrameType frameType, int streamId) => $"The client sent a {frameType} frame with even stream ID {streamId}.";