Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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)");
            }
        }
Exemplo n.º 3
0
        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();
            }
        }
Exemplo n.º 4
0
        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();
            }
        }
Exemplo n.º 5
0
 protected static string GetName(Http2ProtocolErrorCode code) =>
 // These strings are the names used in the HTTP2 spec and should not be localized.
 code switch
 {
Exemplo n.º 6
0
 public Http2ProtocolException(string message, Http2ProtocolErrorCode protocolError)
     : base(message)
 {
     ProtocolError = protocolError;
 }
Exemplo n.º 7
0
 public Http2StreamException(Http2ProtocolErrorCode protocolError)
     : base(SR.Format(SR.net_http_http2_stream_error, GetName(protocolError), ((int)protocolError).ToString("x")), protocolError)
 {
 }
Exemplo n.º 8
0
 public Http2ProtocolException(Http2ProtocolErrorCode protocolError)
     : base(SR.Format(SR.net_http_http2_protocol_error, GetName(protocolError), ((int)protocolError).ToString("x")))
 {
     ProtocolError = protocolError;
 }
Exemplo n.º 9
0
        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));
        }