private async Task SendRstStreamFrameAsync(int streamId, Http2ProtocolErrorCode errorCode) { WriteFrameHeader(new FrameHeader(FrameHeader.RstStreamLength, FrameType.RstStream, FrameFlags.None, streamId)); _outgoingBuffer.AvailableSpan[0] = (byte)(((int)errorCode & 0xFF000000) >> 24); _outgoingBuffer.AvailableSpan[1] = (byte)(((int)errorCode & 0x00FF0000) >> 16); _outgoingBuffer.AvailableSpan[2] = (byte)(((int)errorCode & 0x0000FF00) >> 8); _outgoingBuffer.AvailableSpan[3] = (byte)((int)errorCode & 0x000000FF); _outgoingBuffer.Commit(FrameHeader.RstStreamLength); await FlushOutgoingBytesAsync().ConfigureAwait(false); }
protected static string GetName(Http2ProtocolErrorCode code) { // These strings are the names used in the HTTP2 spec and should not be localized. switch (code) { case Http2ProtocolErrorCode.NoError: return("NO_ERROR"); case Http2ProtocolErrorCode.ProtocolError: return("PROTOCOL_ERROR"); case Http2ProtocolErrorCode.InternalError: return("INTERNAL_ERROR"); case Http2ProtocolErrorCode.FlowControlError: return("FLOW_CONTROL_ERROR"); case Http2ProtocolErrorCode.SettingsTimeout: return("SETTINGS_TIMEOUT"); case Http2ProtocolErrorCode.StreamClosed: return("STREAM_CLOSED"); case Http2ProtocolErrorCode.FrameSizeError: return("FRAME_SIZE_ERROR"); case Http2ProtocolErrorCode.RefusedStream: return("REFUSED_STREAM"); case Http2ProtocolErrorCode.Cancel: return("CANCEL"); case Http2ProtocolErrorCode.CompressionError: return("COMPRESSION_ERROR"); case Http2ProtocolErrorCode.ConnectError: return("CONNECT_ERROR"); case Http2ProtocolErrorCode.EnhanceYourCalm: return("ENHANCE_YOUR_CALM"); case Http2ProtocolErrorCode.InadequateSecurity: return("INADEQUATE_SECURITY"); case Http2ProtocolErrorCode.Http11Required: return("HTTP_1_1_REQUIRED"); default: return("(unknown error)"); } }
private async Task SendRstStreamAsync(int streamId, Http2ProtocolErrorCode errorCode) { await AcquireWriteLockAsync().ConfigureAwait(false); try { _outgoingBuffer.EnsureAvailableSpace(FrameHeader.Size + FrameHeader.RstStreamLength); WriteFrameHeader(new FrameHeader(FrameHeader.RstStreamLength, FrameType.RstStream, FrameFlags.None, streamId)); BinaryPrimitives.WriteInt32BigEndian(_outgoingBuffer.AvailableSpan, (int)errorCode); _outgoingBuffer.Commit(FrameHeader.RstStreamLength); await FlushOutgoingBytesAsync().ConfigureAwait(false); } finally { ReleaseWriteLock(); } }
private async ValueTask SendRstStreamAsync(int streamId, Http2ProtocolErrorCode errorCode) { await AcquireWriteLockAsync().ConfigureAwait(false); try { _outgoingBuffer.EnsureAvailableSpace(FrameHeader.Size + FrameHeader.RstStreamLength); WriteFrameHeader(new FrameHeader(FrameHeader.RstStreamLength, FrameType.RstStream, FrameFlags.None, streamId)); _outgoingBuffer.AvailableSpan[0] = (byte)(((int)errorCode & 0xFF000000) >> 24); _outgoingBuffer.AvailableSpan[1] = (byte)(((int)errorCode & 0x00FF0000) >> 16); _outgoingBuffer.AvailableSpan[2] = (byte)(((int)errorCode & 0x0000FF00) >> 8); _outgoingBuffer.AvailableSpan[3] = (byte)((int)errorCode & 0x000000FF); _outgoingBuffer.Commit(FrameHeader.RstStreamLength); await FlushOutgoingBytesAsync().ConfigureAwait(false); } finally { ReleaseWriteLock(); } }
protected static string GetName(Http2ProtocolErrorCode code) => // These strings are the names used in the HTTP2 spec and should not be localized. code switch {
public Http2ProtocolException(string message, Http2ProtocolErrorCode protocolError) : base(message) { ProtocolError = protocolError; }
public Http2StreamException(Http2ProtocolErrorCode protocolError) : base(SR.Format(SR.net_http_http2_stream_error, GetName(protocolError), ((int)protocolError).ToString("x")), protocolError) { }
public Http2ProtocolException(Http2ProtocolErrorCode protocolError) : base(SR.Format(SR.net_http_http2_protocol_error, GetName(protocolError), ((int)protocolError).ToString("x"))) { ProtocolError = protocolError; }
internal static HttpProtocolException CreateHttp2ConnectionException(Http2ProtocolErrorCode protocolError) { string message = SR.Format(SR.net_http_http2_connection_error, GetName(protocolError), ((int)protocolError).ToString("x")); return(new HttpProtocolException((long)protocolError, message, null)); }