Skip to content

Commit 9afb790

Browse files
committed
cleanup some HTTP/3 cases
1 parent 633d632 commit 9afb790

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

src/libraries/System.Net.Http/src/System/Net/Http/HttpProtocolException.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.IO;
5+
using System.Net.Quic;
56

67
namespace System.Net.Http
78
{
@@ -47,10 +48,10 @@ internal static HttpProtocolException CreateHttp2ConnectionException(Http2Protoc
4748
return new HttpProtocolException((long)protocolError, message, null);
4849
}
4950

50-
internal static HttpProtocolException CreateHttp3StreamException(Http3ErrorCode protocolError)
51+
internal static HttpProtocolException CreateHttp3StreamException(Http3ErrorCode protocolError, QuicException innerException)
5152
{
5253
string message = SR.Format(SR.net_http_http3_stream_error, GetName(protocolError), ((int)protocolError).ToString("x"));
53-
return new HttpProtocolException((long)protocolError, message, null);
54+
return new HttpProtocolException((long)protocolError, message, innerException);
5455
}
5556

5657
internal static HttpProtocolException CreateHttp3ConnectionException(Http3ErrorCode protocolError, string? message = null)

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http3RequestStream.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -252,27 +252,17 @@ await Task.WhenAny(sendContentTask, readResponseTask).ConfigureAwait(false) == s
252252
{
253253
case Http3ErrorCode.VersionFallback:
254254
// The server is requesting us fall back to an older HTTP version.
255-
throw new HttpRequestException(SR.net_http_retry_on_older_version, ex, RequestRetryType.RetryOnLowerHttpVersion, httpRequestError: HttpRequestError.VersionNegotiationError);
255+
throw new HttpRequestException(SR.net_http_retry_on_older_version, ex, RequestRetryType.RetryOnLowerHttpVersion);
256256

257257
case Http3ErrorCode.RequestRejected:
258258
// The server is rejecting the request without processing it, retry it on a different connection.
259-
throw new HttpRequestException(SR.net_http_request_aborted, ex, RequestRetryType.RetryOnConnectionFailure, httpRequestError: HttpRequestError.Unknown);
259+
HttpProtocolException rejectedException = HttpProtocolException.CreateHttp3StreamException(code, ex);
260+
throw new HttpRequestException(SR.net_http_request_aborted, rejectedException, RequestRetryType.RetryOnConnectionFailure, httpRequestError: HttpRequestError.HttpProtocolError);
260261

261262
default:
262263
// Our stream was reset.
263-
HttpRequestError httpRequestError;
264-
Exception innerException;
265-
if (_connection.AbortException != null)
266-
{
267-
httpRequestError = HttpRequestError.Unknown;
268-
innerException = _connection.AbortException;
269-
}
270-
else
271-
{
272-
httpRequestError = HttpRequestError.HttpProtocolError;
273-
innerException = HttpProtocolException.CreateHttp3StreamException(code);
274-
}
275-
throw new HttpRequestException(SR.net_http_client_execution_error, innerException, httpRequestError: httpRequestError);
264+
var innerException = HttpProtocolException.CreateHttp3StreamException(code, ex);
265+
throw new HttpRequestException(SR.net_http_client_execution_error, innerException, httpRequestError: HttpRequestError.HttpProtocolError);
276266
}
277267
}
278268
catch (QuicException ex) when (ex.QuicError == QuicError.ConnectionAborted)
@@ -1265,7 +1255,7 @@ private void HandleReadResponseContentException(Exception ex, CancellationToken
12651255
case QuicException e when (e.QuicError == QuicError.StreamAborted):
12661256
// Peer aborted the stream
12671257
Debug.Assert(e.ApplicationErrorCode.HasValue);
1268-
throw HttpProtocolException.CreateHttp3StreamException((Http3ErrorCode)e.ApplicationErrorCode.Value);
1258+
throw HttpProtocolException.CreateHttp3StreamException((Http3ErrorCode)e.ApplicationErrorCode.Value, e);
12691259

12701260
case QuicException e when (e.QuicError == QuicError.ConnectionAborted):
12711261
// Our connection was reset. Start aborting the connection.

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ public async ValueTask<HttpResponseMessage> SendWithVersionDetectionAndRetryAsyn
11651165
// Throw if fallback is not allowed by the version policy.
11661166
if (request.VersionPolicy != HttpVersionPolicy.RequestVersionOrLower)
11671167
{
1168-
throw new HttpRequestException(SR.Format(SR.net_http_requested_version_server_refused, request.Version, request.VersionPolicy), e);
1168+
throw new HttpRequestException(SR.Format(SR.net_http_requested_version_server_refused, request.Version, request.VersionPolicy), e, httpRequestError: HttpRequestError.VersionNegotiationError);
11691169
}
11701170

11711171
if (NetEventSource.Log.IsEnabled())

0 commit comments

Comments
 (0)