未验证 提交 75ede832 编写于 作者: T TimTim 提交者: GitHub

[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
上级 ef9e276c
......@@ -999,7 +999,7 @@ internal void HandleAltSvc(IEnumerable<string> altSvcHeaderValues, TimeSpan? res
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))
{
......
......@@ -28,7 +28,7 @@ private HttpClient CreateHttpClient(Version version)
[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 @@ fromVersion.Major switch
// 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<HttpResponseMessage> 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 @@ fromVersion.Major switch
await AltSvc_Upgrade_Success(firstServer, secondServer, client);
}
public static TheoryData<Version> AltSvcHeaderUpgradeVersions =>
new TheoryData<Version>
public static TheoryData<Version, bool> AltSvcHeaderUpgradeVersions =>
new TheoryData<Version, bool>
{
{ HttpVersion.Version11 },
{ HttpVersion.Version20 }
{ HttpVersion.Version11, true },
{ HttpVersion.Version11, false },
{ HttpVersion.Version20, true },
{ HttpVersion.Version20, false }
};
[Fact]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册