From: TimTim Date: Fri, 11 Jun 2021 14:08:57 +0000 (+0800) Subject: [HTTP/3] Fix #53632 by using original host when omitted (#53648) X-Git-Tag: submit/tizen/20210909.063632~825 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=75ede83214700ba49b70c0ac746c3541ef219a91;p=platform%2Fupstream%2Fdotnet%2Fruntime.git [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 --- 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]