Skip to content

Fix and test HttpSys delegation #36677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 50 additions & 8 deletions AspNetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,10 @@ Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "WindowsHostingBundle", "src
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServerComparison.TestSites", "src\Servers\testassets\ServerComparison.TestSites\ServerComparison.TestSites.csproj", "{56DFE643-7F0F-40C8-9F7F-8EA5357781EF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DelegationSite", "src\Servers\HttpSys\test\testassets\DelegationSite\DelegationSite.csproj", "{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.HttpSys.NonHelixTests", "src\Servers\HttpSys\test\NonHelixTests\Microsoft.AspNetCore.Server.HttpSys.NonHelixTests.csproj", "{8EB0B983-8851-4565-B92F-366F1B126E61}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -9990,44 +9994,42 @@ Global
{6D365C86-3158-49F5-A21D-506C1E06E870}.Release|x86.Build.0 = Release|Any CPU
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Debug|Any CPU.Build.0 = Debug|Any CPU
{564CABB8-1B3F-4D9E-909D-260EF2B8614A}.Debug|arm64.ActiveCfg = Debug|Any CPU
{564CABB8-1B3F-4D9E-909D-260EF2B8614A}.Debug|arm64.Build.0 = Debug|Any CPU
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Debug|arm64.ActiveCfg = Debug|Any CPU
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Debug|x64.ActiveCfg = Debug|Any CPU
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Debug|x64.Build.0 = Debug|Any CPU
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Debug|x86.ActiveCfg = Debug|Any CPU
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Debug|x86.Build.0 = Debug|Any CPU
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Release|Any CPU.Build.0 = Release|Any CPU
{564CABB8-1B3F-4D9E-909D-260EF2B8614A}.Release|arm64.ActiveCfg = Release|Any CPU
{564CABB8-1B3F-4D9E-909D-260EF2B8614A}.Release|arm64.Build.0 = Release|Any CPU
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Release|arm64.ActiveCfg = Release|Any CPU
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Release|x64.ActiveCfg = Release|Any CPU
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Release|x64.Build.0 = Release|Any CPU
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Release|x86.ActiveCfg = Release|Any CPU
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Release|x86.Build.0 = Release|Any CPU
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF4CEC18-798D-46EC-B0A0-98D97496590F}.Debug|arm64.ActiveCfg = Debug|Any CPU
{CF4CEC18-798D-46EC-B0A0-98D97496590F}.Debug|arm64.Build.0 = Debug|Any CPU
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Debug|arm64.ActiveCfg = Debug|Any CPU
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Debug|x64.ActiveCfg = Debug|Any CPU
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Debug|x64.Build.0 = Debug|Any CPU
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Debug|x86.ActiveCfg = Debug|Any CPU
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Debug|x86.Build.0 = Debug|Any CPU
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Release|Any CPU.Build.0 = Release|Any CPU
{CF4CEC18-798D-46EC-B0A0-98D97496590F}.Release|arm64.ActiveCfg = Release|Any CPU
{CF4CEC18-798D-46EC-B0A0-98D97496590F}.Release|arm64.Build.0 = Release|Any CPU
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Release|arm64.ActiveCfg = Release|Any CPU
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Release|x64.ActiveCfg = Release|Any CPU
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Release|x64.Build.0 = Release|Any CPU
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Release|x86.ActiveCfg = Release|Any CPU
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Release|x86.Build.0 = Release|Any CPU
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Debug|arm64.ActiveCfg = Debug|Any CPU
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Debug|x64.ActiveCfg = Debug|Any CPU
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Debug|x64.Build.0 = Debug|Any CPU
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Debug|x86.ActiveCfg = Debug|Any CPU
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Debug|x86.Build.0 = Debug|Any CPU
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Release|Any CPU.Build.0 = Release|Any CPU
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Release|arm64.ActiveCfg = Release|Any CPU
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Release|x64.ActiveCfg = Release|Any CPU
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Release|x64.Build.0 = Release|Any CPU
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Release|x86.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -10128,10 +10130,16 @@ Global
{B2D7BD12-5BDF-47F5-A55B-4A09D705731F}.Release|x64.Build.0 = Release|Any CPU
{B2D7BD12-5BDF-47F5-A55B-4A09D705731F}.Release|x86.ActiveCfg = Release|Any CPU
{B2D7BD12-5BDF-47F5-A55B-4A09D705731F}.Release|x86.Build.0 = Release|Any CPU
{FD819B29-9EFE-4102-BD0A-375A63051458}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FD819B29-9EFE-4102-BD0A-375A63051458}.Debug|arm64.ActiveCfg = Debug|Any CPU
{FD819B29-9EFE-4102-BD0A-375A63051458}.Debug|arm64.Build.0 = Debug|Any CPU
{FD819B29-9EFE-4102-BD0A-375A63051458}.Debug|x64.ActiveCfg = Debug|Any CPU
{FD819B29-9EFE-4102-BD0A-375A63051458}.Debug|x86.ActiveCfg = Debug|Any CPU
{FD819B29-9EFE-4102-BD0A-375A63051458}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FD819B29-9EFE-4102-BD0A-375A63051458}.Release|arm64.ActiveCfg = Release|Any CPU
{FD819B29-9EFE-4102-BD0A-375A63051458}.Release|arm64.Build.0 = Release|Any CPU
{FD819B29-9EFE-4102-BD0A-375A63051458}.Release|x64.ActiveCfg = Release|Any CPU
{FD819B29-9EFE-4102-BD0A-375A63051458}.Release|x86.ActiveCfg = Release|Any CPU
{53EA8180-8942-4D16-B92A-C5D3813D47CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{53EA8180-8942-4D16-B92A-C5D3813D47CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{53EA8180-8942-4D16-B92A-C5D3813D47CE}.Debug|arm64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -10336,6 +10344,38 @@ Global
{56DFE643-7F0F-40C8-9F7F-8EA5357781EF}.Release|x64.Build.0 = Release|x64
{56DFE643-7F0F-40C8-9F7F-8EA5357781EF}.Release|x86.ActiveCfg = Release|x86
{56DFE643-7F0F-40C8-9F7F-8EA5357781EF}.Release|x86.Build.0 = Release|x86
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Debug|arm64.ActiveCfg = Debug|Any CPU
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Debug|arm64.Build.0 = Debug|Any CPU
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Debug|x64.ActiveCfg = Debug|Any CPU
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Debug|x64.Build.0 = Debug|Any CPU
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Debug|x86.ActiveCfg = Debug|Any CPU
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Debug|x86.Build.0 = Debug|Any CPU
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Release|Any CPU.Build.0 = Release|Any CPU
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Release|arm64.ActiveCfg = Release|Any CPU
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Release|arm64.Build.0 = Release|Any CPU
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Release|x64.ActiveCfg = Release|Any CPU
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Release|x64.Build.0 = Release|Any CPU
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Release|x86.ActiveCfg = Release|Any CPU
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Release|x86.Build.0 = Release|Any CPU
{8EB0B983-8851-4565-B92F-366F1B126E61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8EB0B983-8851-4565-B92F-366F1B126E61}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8EB0B983-8851-4565-B92F-366F1B126E61}.Debug|arm64.ActiveCfg = Debug|Any CPU
{8EB0B983-8851-4565-B92F-366F1B126E61}.Debug|arm64.Build.0 = Debug|Any CPU
{8EB0B983-8851-4565-B92F-366F1B126E61}.Debug|x64.ActiveCfg = Debug|Any CPU
{8EB0B983-8851-4565-B92F-366F1B126E61}.Debug|x64.Build.0 = Debug|Any CPU
{8EB0B983-8851-4565-B92F-366F1B126E61}.Debug|x86.ActiveCfg = Debug|Any CPU
{8EB0B983-8851-4565-B92F-366F1B126E61}.Debug|x86.Build.0 = Debug|Any CPU
{8EB0B983-8851-4565-B92F-366F1B126E61}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8EB0B983-8851-4565-B92F-366F1B126E61}.Release|Any CPU.Build.0 = Release|Any CPU
{8EB0B983-8851-4565-B92F-366F1B126E61}.Release|arm64.ActiveCfg = Release|Any CPU
{8EB0B983-8851-4565-B92F-366F1B126E61}.Release|arm64.Build.0 = Release|Any CPU
{8EB0B983-8851-4565-B92F-366F1B126E61}.Release|x64.ActiveCfg = Release|Any CPU
{8EB0B983-8851-4565-B92F-366F1B126E61}.Release|x64.Build.0 = Release|Any CPU
{8EB0B983-8851-4565-B92F-366F1B126E61}.Release|x86.ActiveCfg = Release|Any CPU
{8EB0B983-8851-4565-B92F-366F1B126E61}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -11186,6 +11226,8 @@ Global
{5244BC49-2568-4701-80A6-EAB8950AB5FA} = {31854B06-DC6B-4416-97C3-559CC390B8B4}
{6F1B115C-1903-40CB-837D-7961AB610F4E} = {5E46DC83-C39C-4E3A-B242-C064607F4367}
{56DFE643-7F0F-40C8-9F7F-8EA5357781EF} = {3CBC4802-E9B8-48B7-BC8C-B0AFB9EEC643}
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D} = {C3722C5D-E159-4AB3-AF60-769185B31B47}
{8EB0B983-8851-4565-B92F-366F1B126E61} = {C3722C5D-E159-4AB3-AF60-769185B31B47}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3E8720B3-DBDD-498C-B383-2CC32A054E8F}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public override async Task<DeploymentResult> DeployAsync()
HostProcess.EnableRaisingEvents = true;
HostProcess.OutputDataReceived += (sender, dataArgs) =>
{
if (string.Equals(dataArgs.Data, ApplicationStartedMessage))
if (!string.IsNullOrEmpty(dataArgs.Data) && dataArgs.Data.Contains(ApplicationStartedMessage))
{
started.TrySetResult();
}
Expand Down
2 changes: 2 additions & 0 deletions src/Servers/HttpSys/HttpSysServer.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"src\\Servers\\HttpSys\\samples\\TestClient\\TestClient.csproj",
"src\\Servers\\HttpSys\\src\\Microsoft.AspNetCore.Server.HttpSys.csproj",
"src\\Servers\\HttpSys\\test\\FunctionalTests\\Microsoft.AspNetCore.Server.HttpSys.FunctionalTests.csproj",
"src\\Servers\\HttpSys\\test\\NonHelixTests\\Microsoft.AspNetCore.Server.HttpSys.NonHelixTests.csproj",
"src\\Servers\\HttpSys\\test\\Tests\\Microsoft.AspNetCore.Server.HttpSys.Tests.csproj",
"src\\Servers\\HttpSys\\test\\testassets\\DelegationSite\\DelegationSite.csproj",
"src\\Servers\\IIS\\IISIntegration\\src\\Microsoft.AspNetCore.Server.IISIntegration.csproj",
"src\\Servers\\IIS\\IIS\\src\\Microsoft.AspNetCore.Server.IIS.csproj",
"src\\Servers\\Kestrel\\Core\\src\\Microsoft.AspNetCore.Server.Kestrel.Core.csproj",
Expand Down
2 changes: 1 addition & 1 deletion src/Servers/HttpSys/src/MessagePump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public MessagePump(IOptions<HttpSysOptions> options, ILoggerFactory loggerFactor
_serverAddresses = new ServerAddressesFeature();
Features.Set<IServerAddressesFeature>(_serverAddresses);

if (HttpApi.IsFeatureSupported(HttpApiTypes.HTTP_FEATURE_ID.HttpFeatureDelegateEx))
if (HttpApi.SupportsDelegation)
{
var delegationProperty = new ServerDelegationPropertyFeature(Listener.RequestQueue, _logger);
Features.Set<IServerDelegationFeature>(delegationProperty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@
<Reference Include="Microsoft.Net.Http.Headers" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Microsoft.AspNetCore.Server.HttpSys.FunctionalTests" />
<InternalsVisibleTo Include="Microsoft.AspNetCore.Server.HttpSys.NonHelixTests" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions src/Servers/HttpSys/src/NativeInterop/HttpApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ internal static HTTP_API_VERSION ApiVersion
internal static bool SupportsTrailers { get; private set; }
[MemberNotNullWhen(true, nameof(HttpSetRequestProperty))]
internal static bool SupportsReset { get; private set; }
internal static bool SupportsDelegation { get; private set; }

static HttpApi()
{
Expand All @@ -136,18 +137,17 @@ private static void InitHttpApi(ushort majorVersion, ushort minorVersion)
version.HttpApiMajorVersion = majorVersion;
version.HttpApiMinorVersion = minorVersion;

var statusCode = HttpInitialize(version, (uint)HTTP_FLAGS.HTTP_INITIALIZE_SERVER, null);
var statusCode = HttpInitialize(version, (uint)(HTTP_FLAGS.HTTP_INITIALIZE_SERVER | HTTP_FLAGS.HTTP_INITIALIZE_CONFIG), null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happen on older OSes that don't have this API?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTTP_INITIALIZE_CONFIG isn't a new flag, I think it's been around forever. What changed is that HttpIsFeatureSupported now requires it.


supported = statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS;

if (supported)
{
HttpApiModule = SafeLibraryHandle.Open(HTTPAPI);
HttpSetRequestProperty = HttpApiModule.GetProcAddress<HttpSetRequestPropertyInvoker>("HttpSetRequestProperty", throwIfNotFound: false);

SupportsReset = HttpSetRequestProperty != null;
// Trailers support was added in the same release as Reset, but there's no method we can export to check it directly.
SupportsTrailers = SupportsReset;
SupportsTrailers = IsFeatureSupported(HTTP_FEATURE_ID.HttpFeatureResponseTrailers);
SupportsDelegation = IsFeatureSupported(HTTP_FEATURE_ID.HttpFeatureDelegateEx);
}
}

Expand All @@ -160,7 +160,7 @@ internal static bool Supported
}
}

internal static bool IsFeatureSupported(HTTP_FEATURE_ID feature)
private static bool IsFeatureSupported(HTTP_FEATURE_ID feature)
{
try
{
Expand Down
6 changes: 0 additions & 6 deletions src/Servers/HttpSys/src/Properties/AssemblyInfo.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Servers/HttpSys/src/StandardFeatureCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static StandardFeatureCollection()
_featureFuncLookup[typeof(ITlsHandshakeFeature)] = ctx => ctx.GetTlsHandshakeFeature();
}

if (HttpApi.IsFeatureSupported(HttpApiTypes.HTTP_FEATURE_ID.HttpFeatureDelegateEx))
if (HttpApi.SupportsDelegation)
{
_featureFuncLookup[typeof(IHttpSysRequestDelegationFeature)] = _identityFunc;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Testing;
using static Microsoft.AspNetCore.HttpSys.Internal.HttpApiTypes;

namespace Microsoft.AspNetCore.Server.HttpSys.FunctionalTests
{
Expand All @@ -17,14 +11,8 @@ public class DelegateSupportedConditionAttribute : Attribute, ITestCondition
private readonly bool _isSupported;
public DelegateSupportedConditionAttribute(bool isSupported) => _isSupported = isSupported;

private readonly Lazy<bool> _isDelegateSupported = new Lazy<bool>(CanDelegate);
public bool IsMet => (_isDelegateSupported.Value == _isSupported);
public bool IsMet => HttpApi.SupportsDelegation == _isSupported;

public string SkipReason => $"Http.Sys does {(_isSupported ? "not" : "")} support delegating requests";

private static bool CanDelegate()
{
return HttpApi.IsFeatureSupported(HTTP_FEATURE_ID.HttpFeatureDelegateEx);
}
}
}
3 changes: 3 additions & 0 deletions src/Servers/HttpSys/test/FunctionalTests/DelegateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ public async Task DelegateAfterRequestBodyReadShouldThrow()
[DelegateSupportedCondition(false)]
public async Task DelegationFeaturesAreNull()
{
// Testing the DelegateSupportedCondition
Assert.True(Environment.OSVersion.Version < new Version(10, 0, 22000), "This should be supported on Win 11.");

using var delegator = Utilities.CreateHttpServer(out var delegatorAddress, httpContext =>
{
var delegateFeature = httpContext.Features.Get<IHttpSysRequestDelegationFeature>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Net.Http;
using Microsoft.AspNetCore.Server.IntegrationTesting;
using Microsoft.AspNetCore.Testing;
using Xunit.Abstractions;

namespace Microsoft.AspNetCore.Server.HttpSys.NonHelixTests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why we don't want these to run on helix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We never figured out how to make them work there. #8247

{
public class DelegateOutOfProcTests : LoggedTest
{
public DelegateOutOfProcTests(ITestOutputHelper output) : base(output) { }

[ConditionalFact]
[DelegateSupportedCondition(true)]
public async Task CanDelegateOutOfProcess()
{
using var _ = StartLog(out var loggerFactory);

var logger = loggerFactory.CreateLogger("CanDelegateOutOfProcess");

// https://github.com/dotnet/aspnetcore/issues/8247
#pragma warning disable 0618
var applicationPath = Path.Combine(TestPathUtilities.GetSolutionRootDirectory("HttpSysServer"), "test", "testassets",
"DelegationSite");
#pragma warning restore 0618

var deploymentParameters = new DeploymentParameters(
applicationPath,
ServerType.HttpSys,
RuntimeFlavor.CoreClr,
RuntimeArchitecture.x64)
{
EnvironmentName = "Testing",
TargetFramework = Tfm.Default,
ApplicationType = ApplicationType.Portable,
PublishApplicationBeforeDeployment = true,
StatusMessagesEnabled = true
};

var queueName = Guid.NewGuid().ToString();
deploymentParameters.EnvironmentVariables["queue"] = queueName;

using var deployer = new SelfHostDeployer(deploymentParameters, loggerFactory);
var deploymentResult = await deployer.DeployAsync().DefaultTimeout();

// Make sure the deployment really worked
var responseString = await deploymentResult.HttpClient.GetStringAsync("").DefaultTimeout();
Assert.Equal("Hello from delegatee", responseString);

DelegationRule destination = default;
using var delegator = Utilities.CreateHttpServer(out var delegatorAddress, httpContext =>
{
var delegateFeature = httpContext.Features.Get<IHttpSysRequestDelegationFeature>();
delegateFeature.DelegateRequest(destination);
return Task.CompletedTask;
});

var delegationProperty = delegator.Features.Get<IServerDelegationFeature>();
using (destination = delegationProperty.CreateDelegationRule(queueName, deploymentResult.ApplicationBaseUri))
{
// Send a request to the delegator that gets transfered to the delegatee in the other process.
using var client = new HttpClient();
responseString = await client.GetStringAsync(delegatorAddress).DefaultTimeout();
Assert.Equal("Hello from delegatee", responseString);
}
}
}
}
Loading