This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Clean up HTTP/2 protocol exception handling #37223
Merged
stephentoub
merged 2 commits into
dotnet:master
from
stephentoub:http2protocolexception
Apr 29, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2ProtocolErrorCode.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| namespace System.Net.Http | ||
| { | ||
| // NOTE: If any additional error codes are added here, they should also be added to Http2ProtocolException's mapping. | ||
|
|
||
| /// <summary> | ||
| /// Error codes defined by the HTTP/2 protocol, used in RST_STREAM and GOAWAY frames to convey the reasons for the stream or connection error. | ||
| /// https://http2.github.io/http2-spec/#PROTOCOL_ERROR | ||
| /// </summary> | ||
| internal enum Http2ProtocolErrorCode | ||
| { | ||
| /// <summary>The associated condition is not a result of an error.</summary> | ||
| NoError = 0x0, | ||
| /// <summary>The endpoint detected an unspecific protocol error. This error is for use when a more specific error code is not available.</summary> | ||
| ProtocolError = 0x1, | ||
| /// <summary>The endpoint encountered an unexpected internal error.</summary> | ||
| InternalError = 0x2, | ||
| /// <summary>The endpoint detected that its peer violated the flow-control protocol.</summary> | ||
| FlowControlError = 0x3, | ||
| /// <summary>The endpoint sent a SETTINGS frame but did not receive a response in a timely manner.</summary> | ||
| SettingsTimeout = 0x4, | ||
| /// <summary>The endpoint received a frame after a stream was half-closed.</summary> | ||
| StreamClosed = 0x5, | ||
| /// <summary>The endpoint received a frame with an invalid size.</summary> | ||
| FrameSizeError = 0x6, | ||
| /// <summary>The endpoint refused the stream prior to performing any application processing.</summary> | ||
| RefusedStream = 0x7, | ||
| /// <summary>Used by the endpoint to indicate that the stream is no longer needed.</summary> | ||
| Cancel = 0x8, | ||
| /// <summary>The endpoint is unable to maintain the header compression context for the connection.</summary> | ||
| CompressionError = 0x9, | ||
| /// <summary>The connection established in response to a CONNECT request was reset or abnormally closed.</summary> | ||
| ConnectError = 0xa, | ||
| /// <summary>The endpoint detected that its peer is exhibiting a behavior that might be generating excessive load.</summary> | ||
| EnhanceYourCalm = 0xb, | ||
| /// <summary>The underlying transport has properties that do not meet minimum security requirements.</summary> | ||
| InadequateSecurity = 0xc, | ||
| /// <summary>The endpoint requires that HTTP/1.1 be used instead of HTTP/2.</summary> | ||
| Http11Required = 0xd | ||
| } | ||
| } |
69 changes: 69 additions & 0 deletions
69
src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2ProtocolException.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.Diagnostics; | ||
| using System.Runtime.Serialization; | ||
|
|
||
| namespace System.Net.Http | ||
| { | ||
| [Serializable] | ||
| internal sealed class Http2ProtocolException : Exception | ||
| { | ||
| public Http2ProtocolException(Http2ProtocolErrorCode protocolError) | ||
| : base(SR.Format(SR.net_http_http2_protocol_error, GetName(protocolError), ((int)protocolError).ToString("x"))) | ||
| { | ||
| ProtocolError = protocolError; | ||
| } | ||
|
|
||
| private Http2ProtocolException(SerializationInfo info, StreamingContext context) : base(info, context) | ||
| { | ||
| ProtocolError = (Http2ProtocolErrorCode)info.GetInt32(nameof(ProtocolError)); | ||
| } | ||
|
|
||
| public override void GetObjectData(SerializationInfo info, StreamingContext context) | ||
| { | ||
| info.AddValue(nameof(ProtocolError), (int)ProtocolError); | ||
| base.GetObjectData(info, context); | ||
| } | ||
|
|
||
| internal Http2ProtocolErrorCode ProtocolError { get; } | ||
|
|
||
| private 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"; | ||
| default: // any unrecognized error code is treated as a protocol 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"; | ||
|
stephentoub marked this conversation as resolved.
|
||
| case Http2ProtocolErrorCode.InadequateSecurity: | ||
| return "INADEQUATE_SECURITY"; | ||
| case Http2ProtocolErrorCode.Http11Required: | ||
| return "HTTP_1_1_REQUIRED"; | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.