From 75ede83214700ba49b70c0ac746c3541ef219a91 Mon Sep 17 00:00:00 2001 From: TimTim Date: Fri, 11 Jun 2021 22:08:57 +0800 Subject: [PATCH] [HTTP/3] Fix #53632 by using original host when omitted (#53648) * Fix #53632 * Annotate non-nullable _originAuthority * Test inheriting original host for HTTP/3 Alt-Svc --- .../Net/Http/SocketsHttpHandler/HttpConnectionPool.cs | 2 +- .../FunctionalTests/HttpClientHandlerTest.AltSvc.cs | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs index 250aba3..00a1a37 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs @@ -999,7 +999,7 @@ namespace System.Net.Http if (nextAuthority == null && value != null && value.AlpnProtocolName == "h3") { - var authority = new HttpAuthority(value.Host!, value.Port); + var authority = new HttpAuthority(value.Host ?? _originAuthority!.IdnHost, value.Port); if (IsAltSvcBlocked(authority)) { diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AltSvc.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AltSvc.cs index ff6ec71..b56398b 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AltSvc.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.AltSvc.cs @@ -28,7 +28,7 @@ namespace System.Net.Http.Functional.Tests [Theory] [MemberData(nameof(AltSvcHeaderUpgradeVersions))] - public async Task AltSvc_Header_Upgrade_Success(Version fromVersion) + public async Task AltSvc_Header_Upgrade_Success(Version fromVersion, bool overrideHost) { // The test makes a request to a HTTP/1 or HTTP/2 server first, which supplies an Alt-Svc header pointing to the second server. using GenericLoopbackServer firstServer = @@ -41,13 +41,16 @@ namespace System.Net.Http.Functional.Tests // The second request is expected to come in on this HTTP/3 server. using Http3LoopbackServer secondServer = CreateHttp3LoopbackServer(); + + if (!overrideHost) + Assert.Equal(firstServer.Address.IdnHost, secondServer.Address.IdnHost); using HttpClient client = CreateHttpClient(fromVersion); Task firstResponseTask = client.GetAsync(firstServer.Address); Task serverTask = firstServer.AcceptConnectionSendResponseAndCloseAsync(additionalHeaders: new[] { - new HttpHeaderData("Alt-Svc", $"h3=\"{secondServer.Address.IdnHost}:{secondServer.Address.Port}\"") + new HttpHeaderData("Alt-Svc", $"h3=\"{(overrideHost ? secondServer.Address.IdnHost : null)}:{secondServer.Address.Port}\"") }); await new[] { firstResponseTask, serverTask }.WhenAllOrAnyFailed(30_000); @@ -58,11 +61,13 @@ namespace System.Net.Http.Functional.Tests await AltSvc_Upgrade_Success(firstServer, secondServer, client); } - public static TheoryData AltSvcHeaderUpgradeVersions => - new TheoryData + public static TheoryData AltSvcHeaderUpgradeVersions => + new TheoryData { - { HttpVersion.Version11 }, - { HttpVersion.Version20 } + { HttpVersion.Version11, true }, + { HttpVersion.Version11, false }, + { HttpVersion.Version20, true }, + { HttpVersion.Version20, false } }; [Fact] -- 2.7.4