public void PrepareRstStream(int streamId, Http2ErrorCode errorCode) { PayloadLength = 4; Type = Http2FrameType.RST_STREAM; Flags = 0; StreamId = streamId; RstStreamErrorCode = errorCode; }
public Http2GoawayFrame(Http2FrameHeader header, int lastStreamID, Http2ErrorCode errorCode, byte[] additionalDebugData) { this.Header = header; this.R = false; this.LastStreamID = lastStreamID; this.ErrorCode = errorCode; this.AdditionalDebugData = additionalDebugData; }
public Task WriteRstStreamAsync(int streamId, Http2ErrorCode errorCode) { lock (_writeLock) { _outgoingFrame.PrepareRstStream(streamId, errorCode); return(WriteAsync(_outgoingFrame.Raw)); } }
public Task WriteGoAwayAsync(int lastStreamId, Http2ErrorCode errorCode) { lock (_writeLock) { _outgoingFrame.PrepareGoAway(lastStreamId, errorCode); return(WriteAsync(_outgoingFrame.Raw)); } }
protected void VerifyGoAway(Http2Frame frame, int expectedLastStreamId, Http2ErrorCode expectedErrorCode) { Assert.Equal(Http2FrameType.GOAWAY, frame.Type); Assert.Equal(8, frame.PayloadLength); Assert.Equal(0, frame.Flags); Assert.Equal(0, frame.StreamId); Assert.Equal(expectedLastStreamId, frame.GoAwayLastStreamId); Assert.Equal(expectedErrorCode, frame.GoAwayErrorCode); }
public Http2RstStreamFrame(Http2FrameHeader header, byte[] data) { if (data.Length != header.Length) { throw new ArgumentException("Invalid Length."); } this.Header = header; this.ErrorCode = (Http2ErrorCode)data.ToUInt32(0); }
public void PrepareGoAway(int lastStreamId, Http2ErrorCode errorCode) { PayloadLength = 8; Type = Http2FrameType.GOAWAY; Flags = 0; StreamId = 0; GoAwayLastStreamId = lastStreamId; GoAwayErrorCode = errorCode; }
public ValueTask<FlushResult> WriteRstStreamAsync(Http2ErrorCode error) { lock (_dataWriterLock) { // Always send the reset even if the response body is _completed. The request body may not have completed yet. Stop(); return _frameWriter.WriteRstStreamAsync(StreamId, error); } }
public Task WriteRstStreamAsync(Http2ErrorCode error) { lock (_dataWriterLock) { // Always send the reset even if the response body is _completed. The request body may not have completed yet. Dispose(); return(_frameWriter.WriteRstStreamAsync(_streamId, error)); } }
public static Http2RstStreamFrame Create( int streamID, Http2ErrorCode errorCode) { var header = new Http2FrameHeader( 4, Http2FrameType.RstStream, 0, streamID); return(new Http2RstStreamFrame(header, errorCode)); }
private void ResetAndAbort(ConnectionAbortedException abortReason, Http2ErrorCode error) { if (!TryApplyCompletionFlag(StreamCompletionFlags.Aborted)) { return; } Log.Http2StreamResetAbort(TraceIdentifier, error, abortReason); // Don't block on IO. This never faults. _ = _http2Output.WriteRstStreamAsync(error); AbortCore(abortReason); }
public static Http2GoawayFrame Create( int streamID, int lastStreamID, Http2ErrorCode errorCode, byte[] additionalDebugData) { var header = new Http2FrameHeader( 4 + 4 + additionalDebugData.Length, Http2FrameType.Goaway, 0, streamID); return(new Http2GoawayFrame(header, lastStreamID, errorCode, additionalDebugData)); }
private void ResetAndAbort(ConnectionAbortedException abortReason, Http2ErrorCode error) { if (Interlocked.Exchange(ref _requestAborted, 1) != 0) { return; } Log.Http2StreamResetAbort(TraceIdentifier, error, abortReason); // Don't block on IO. This never faults. _ = _http2Output.WriteRstStreamAsync(error); AbortCore(abortReason); }
protected async Task WaitForStreamErrorAsync(int expectedStreamId, Http2ErrorCode expectedErrorCode, string expectedErrorMessage) { var frame = await ReceiveFrameAsync(); Assert.Equal(Http2FrameType.RST_STREAM, frame.Type); Assert.Equal(4, frame.PayloadLength); Assert.Equal(0, frame.Flags); Assert.Equal(expectedStreamId, frame.StreamId); Assert.Equal(expectedErrorCode, frame.RstStreamErrorCode); if (expectedErrorMessage != null) { Assert.Contains(TestApplicationErrorLogger.Messages, m => m.Exception?.Message.Contains(expectedErrorMessage) ?? false); } }
/* https://tools.ietf.org/html/rfc7540#section-6.8 +-+-------------------------------------------------------------+ |R| Last-Stream-ID (31) | +-+-------------------------------------------------------------+ | Error Code (32) | +---------------------------------------------------------------+ | Additional Debug Data (*) | (not implemented) +---------------------------------------------------------------+ */ public Task WriteGoAwayAsync(int lastStreamId, Http2ErrorCode errorCode) { lock (_writeLock) { _outgoingFrame.PrepareGoAway(lastStreamId, errorCode); WriteHeaderUnsynchronized(); var buffer = _outputWriter.GetSpan(8); Bitshifter.WriteUInt31BigEndian(buffer, (uint)lastStreamId); buffer = buffer.Slice(4); BinaryPrimitives.WriteUInt32BigEndian(buffer, (uint)errorCode); _outputWriter.Advance(8); return(TimeFlushUnsynchronizedAsync()); } }
internal void ResetAndAbort(ConnectionAbortedException abortReason, Http2ErrorCode error) { // Future incoming frames will drain for a default grace period to avoid destabilizing the connection. var states = ApplyCompletionFlag(StreamCompletionFlags.Aborted); if (states.OldState == states.NewState) { return; } Log.Http2StreamResetAbort(TraceIdentifier, error, abortReason); // Don't block on IO. This never faults. _ = _http2Output.WriteRstStreamAsync(error); AbortCore(abortReason); }
/* https://tools.ietf.org/html/rfc7540#section-6.4 +---------------------------------------------------------------+ | Error Code (32) | +---------------------------------------------------------------+ */ public Task WriteRstStreamAsync(int streamId, Http2ErrorCode errorCode) { lock (_writeLock) { if (_completed) { return(Task.CompletedTask); } _outgoingFrame.PrepareRstStream(streamId, errorCode); WriteHeaderUnsynchronized(); var buffer = _outputWriter.GetSpan(4); BinaryPrimitives.WriteUInt32BigEndian(buffer, (uint)errorCode); _outputWriter.Advance(4); return(TimeFlushUnsynchronizedAsync()); } }
private void ResetAndAbort(ConnectionAbortedException abortReason, Http2ErrorCode error) { var states = ApplyCompletionFlag(StreamCompletionFlags.Aborted); if (states.OldState == states.NewState) { return; } try { Log.Http2StreamResetAbort(TraceIdentifier, error, abortReason); // Don't block on IO. This never faults. _ = _http2Output.WriteRstStreamAsync(error); AbortCore(abortReason); } finally { TryFireOnStreamCompleted(states); } }
protected async Task WaitForConnectionErrorAsync <TException>(bool ignoreNonGoAwayFrames, int expectedLastStreamId, Http2ErrorCode expectedErrorCode, string expectedErrorMessage) where TException : Exception { var frame = await ReceiveFrameAsync(); if (ignoreNonGoAwayFrames) { while (frame.Type != Http2FrameType.GOAWAY) { frame = await ReceiveFrameAsync(); } } VerifyGoAway(frame, expectedLastStreamId, expectedErrorCode); if (expectedErrorMessage != null) { var message = Assert.Single(TestApplicationErrorLogger.Messages, m => m.Exception is TException); Assert.Contains(expectedErrorMessage, message.Exception.Message); } await _connectionTask; _pair.Application.Output.Complete(); }
public EncoderException(Http2ErrorCode errorCode, string errorMessage) : base(errorCode, errorMessage) { }
public Http2ConnectionErrorException(string message, Http2ErrorCode errorCode) : base($"HTTP/2 connection error ({errorCode}): {message}") { ErrorCode = errorCode; }
public void Http2StreamResetAbort(string traceIdentifier, Http2ErrorCode error, ConnectionAbortedException abortReason) { }
public Http2ConnectionErrorException(Http2ErrorCode errorCode) : base($"HTTP/2 connection error: {errorCode}") { ErrorCode = errorCode; }
public Http2Exception(Http2ErrorCode httpErrorCode, string message) : base(message) { }
public Http2StreamErrorException(int streamId, string message, Http2ErrorCode errorCode) : base($"HTTP/2 stream ID {streamId} error ({errorCode}): {message}") { StreamId = streamId; ErrorCode = errorCode; }
private async Task WaitForConnectionErrorAsync(PipeReader reader, bool ignoreNonGoAwayFrames, int expectedLastStreamId, Http2ErrorCode expectedErrorCode) { var frame = await ReceiveFrameAsync(reader); if (ignoreNonGoAwayFrames) { while (frame.Type != Http2FrameType.GOAWAY) { frame = await ReceiveFrameAsync(reader); } } Assert.Equal(Http2FrameType.GOAWAY, frame.Type); Assert.Equal(8, frame.PayloadLength); Assert.Equal(0, frame.Flags); Assert.Equal(0, frame.StreamId); Assert.Equal(expectedLastStreamId, frame.GoAwayLastStreamId); Assert.Equal(expectedErrorCode, frame.GoAwayErrorCode); }
public DecoderException(Http2ErrorCode httpErrorCode, string message) : base(httpErrorCode, message) { }
public Http2RstStreamFrame(Http2FrameHeader header, Http2ErrorCode errorCode) { this.Header = header; this.ErrorCode = errorCode; }
internal static string FormatHttp2StreamResetByApplication(Http2ErrorCode errorCode) => $"The HTTP/2 stream was reset by the application with error code {errorCode}.";
public static partial void Http2StreamResetAbort(ILogger logger, string traceIdentifier, Http2ErrorCode error, ConnectionAbortedException abortReason);