Skip to content

Commit f72785f

Browse files
authored
Fix and test HttpSys delegation (dotnet#36677)
1 parent aebbd5c commit f72785f

21 files changed

+360
-39
lines changed

AspNetCore.sln

+50-8
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,10 @@ Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "WindowsHostingBundle", "src
17161716
EndProject
17171717
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServerComparison.TestSites", "src\Servers\testassets\ServerComparison.TestSites\ServerComparison.TestSites.csproj", "{56DFE643-7F0F-40C8-9F7F-8EA5357781EF}"
17181718
EndProject
1719+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DelegationSite", "src\Servers\HttpSys\test\testassets\DelegationSite\DelegationSite.csproj", "{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}"
1720+
EndProject
1721+
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}"
1722+
EndProject
17191723
Global
17201724
GlobalSection(SolutionConfigurationPlatforms) = preSolution
17211725
Debug|Any CPU = Debug|Any CPU
@@ -9990,44 +9994,42 @@ Global
99909994
{6D365C86-3158-49F5-A21D-506C1E06E870}.Release|x86.Build.0 = Release|Any CPU
99919995
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
99929996
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Debug|Any CPU.Build.0 = Debug|Any CPU
9993-
{564CABB8-1B3F-4D9E-909D-260EF2B8614A}.Debug|arm64.ActiveCfg = Debug|Any CPU
9994-
{564CABB8-1B3F-4D9E-909D-260EF2B8614A}.Debug|arm64.Build.0 = Debug|Any CPU
9997+
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Debug|arm64.ActiveCfg = Debug|Any CPU
99959998
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Debug|x64.ActiveCfg = Debug|Any CPU
99969999
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Debug|x64.Build.0 = Debug|Any CPU
999710000
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Debug|x86.ActiveCfg = Debug|Any CPU
999810001
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Debug|x86.Build.0 = Debug|Any CPU
999910002
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Release|Any CPU.ActiveCfg = Release|Any CPU
1000010003
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Release|Any CPU.Build.0 = Release|Any CPU
10001-
{564CABB8-1B3F-4D9E-909D-260EF2B8614A}.Release|arm64.ActiveCfg = Release|Any CPU
10002-
{564CABB8-1B3F-4D9E-909D-260EF2B8614A}.Release|arm64.Build.0 = Release|Any CPU
10004+
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Release|arm64.ActiveCfg = Release|Any CPU
1000310005
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Release|x64.ActiveCfg = Release|Any CPU
1000410006
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Release|x64.Build.0 = Release|Any CPU
1000510007
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Release|x86.ActiveCfg = Release|Any CPU
1000610008
{2A150BE3-D7DC-4E2A-8399-6EBAB77DEF00}.Release|x86.Build.0 = Release|Any CPU
1000710009
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1000810010
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
10009-
{CF4CEC18-798D-46EC-B0A0-98D97496590F}.Debug|arm64.ActiveCfg = Debug|Any CPU
10010-
{CF4CEC18-798D-46EC-B0A0-98D97496590F}.Debug|arm64.Build.0 = Debug|Any CPU
10011+
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Debug|arm64.ActiveCfg = Debug|Any CPU
1001110012
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Debug|x64.ActiveCfg = Debug|Any CPU
1001210013
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Debug|x64.Build.0 = Debug|Any CPU
1001310014
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Debug|x86.ActiveCfg = Debug|Any CPU
1001410015
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Debug|x86.Build.0 = Debug|Any CPU
1001510016
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
1001610017
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Release|Any CPU.Build.0 = Release|Any CPU
10017-
{CF4CEC18-798D-46EC-B0A0-98D97496590F}.Release|arm64.ActiveCfg = Release|Any CPU
10018-
{CF4CEC18-798D-46EC-B0A0-98D97496590F}.Release|arm64.Build.0 = Release|Any CPU
10018+
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Release|arm64.ActiveCfg = Release|Any CPU
1001910019
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Release|x64.ActiveCfg = Release|Any CPU
1002010020
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Release|x64.Build.0 = Release|Any CPU
1002110021
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Release|x86.ActiveCfg = Release|Any CPU
1002210022
{D5F4D764-887D-4EB3-8D00-FCBE23FFDBBC}.Release|x86.Build.0 = Release|Any CPU
1002310023
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1002410024
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
10025+
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Debug|arm64.ActiveCfg = Debug|Any CPU
1002510026
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Debug|x64.ActiveCfg = Debug|Any CPU
1002610027
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Debug|x64.Build.0 = Debug|Any CPU
1002710028
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Debug|x86.ActiveCfg = Debug|Any CPU
1002810029
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Debug|x86.Build.0 = Debug|Any CPU
1002910030
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
1003010031
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Release|Any CPU.Build.0 = Release|Any CPU
10032+
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Release|arm64.ActiveCfg = Release|Any CPU
1003110033
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Release|x64.ActiveCfg = Release|Any CPU
1003210034
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Release|x64.Build.0 = Release|Any CPU
1003310035
{40F493E2-FE59-4787-BE44-3AED39D585BF}.Release|x86.ActiveCfg = Release|Any CPU
@@ -10128,10 +10130,16 @@ Global
1012810130
{B2D7BD12-5BDF-47F5-A55B-4A09D705731F}.Release|x64.Build.0 = Release|Any CPU
1012910131
{B2D7BD12-5BDF-47F5-A55B-4A09D705731F}.Release|x86.ActiveCfg = Release|Any CPU
1013010132
{B2D7BD12-5BDF-47F5-A55B-4A09D705731F}.Release|x86.Build.0 = Release|Any CPU
10133+
{FD819B29-9EFE-4102-BD0A-375A63051458}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1013110134
{FD819B29-9EFE-4102-BD0A-375A63051458}.Debug|arm64.ActiveCfg = Debug|Any CPU
1013210135
{FD819B29-9EFE-4102-BD0A-375A63051458}.Debug|arm64.Build.0 = Debug|Any CPU
10136+
{FD819B29-9EFE-4102-BD0A-375A63051458}.Debug|x64.ActiveCfg = Debug|Any CPU
10137+
{FD819B29-9EFE-4102-BD0A-375A63051458}.Debug|x86.ActiveCfg = Debug|Any CPU
10138+
{FD819B29-9EFE-4102-BD0A-375A63051458}.Release|Any CPU.ActiveCfg = Release|Any CPU
1013310139
{FD819B29-9EFE-4102-BD0A-375A63051458}.Release|arm64.ActiveCfg = Release|Any CPU
1013410140
{FD819B29-9EFE-4102-BD0A-375A63051458}.Release|arm64.Build.0 = Release|Any CPU
10141+
{FD819B29-9EFE-4102-BD0A-375A63051458}.Release|x64.ActiveCfg = Release|Any CPU
10142+
{FD819B29-9EFE-4102-BD0A-375A63051458}.Release|x86.ActiveCfg = Release|Any CPU
1013510143
{53EA8180-8942-4D16-B92A-C5D3813D47CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1013610144
{53EA8180-8942-4D16-B92A-C5D3813D47CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
1013710145
{53EA8180-8942-4D16-B92A-C5D3813D47CE}.Debug|arm64.ActiveCfg = Debug|Any CPU
@@ -10336,6 +10344,38 @@ Global
1033610344
{56DFE643-7F0F-40C8-9F7F-8EA5357781EF}.Release|x64.Build.0 = Release|x64
1033710345
{56DFE643-7F0F-40C8-9F7F-8EA5357781EF}.Release|x86.ActiveCfg = Release|x86
1033810346
{56DFE643-7F0F-40C8-9F7F-8EA5357781EF}.Release|x86.Build.0 = Release|x86
10347+
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
10348+
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Debug|Any CPU.Build.0 = Debug|Any CPU
10349+
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Debug|arm64.ActiveCfg = Debug|Any CPU
10350+
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Debug|arm64.Build.0 = Debug|Any CPU
10351+
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Debug|x64.ActiveCfg = Debug|Any CPU
10352+
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Debug|x64.Build.0 = Debug|Any CPU
10353+
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Debug|x86.ActiveCfg = Debug|Any CPU
10354+
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Debug|x86.Build.0 = Debug|Any CPU
10355+
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Release|Any CPU.ActiveCfg = Release|Any CPU
10356+
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Release|Any CPU.Build.0 = Release|Any CPU
10357+
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Release|arm64.ActiveCfg = Release|Any CPU
10358+
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Release|arm64.Build.0 = Release|Any CPU
10359+
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Release|x64.ActiveCfg = Release|Any CPU
10360+
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Release|x64.Build.0 = Release|Any CPU
10361+
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Release|x86.ActiveCfg = Release|Any CPU
10362+
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D}.Release|x86.Build.0 = Release|Any CPU
10363+
{8EB0B983-8851-4565-B92F-366F1B126E61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
10364+
{8EB0B983-8851-4565-B92F-366F1B126E61}.Debug|Any CPU.Build.0 = Debug|Any CPU
10365+
{8EB0B983-8851-4565-B92F-366F1B126E61}.Debug|arm64.ActiveCfg = Debug|Any CPU
10366+
{8EB0B983-8851-4565-B92F-366F1B126E61}.Debug|arm64.Build.0 = Debug|Any CPU
10367+
{8EB0B983-8851-4565-B92F-366F1B126E61}.Debug|x64.ActiveCfg = Debug|Any CPU
10368+
{8EB0B983-8851-4565-B92F-366F1B126E61}.Debug|x64.Build.0 = Debug|Any CPU
10369+
{8EB0B983-8851-4565-B92F-366F1B126E61}.Debug|x86.ActiveCfg = Debug|Any CPU
10370+
{8EB0B983-8851-4565-B92F-366F1B126E61}.Debug|x86.Build.0 = Debug|Any CPU
10371+
{8EB0B983-8851-4565-B92F-366F1B126E61}.Release|Any CPU.ActiveCfg = Release|Any CPU
10372+
{8EB0B983-8851-4565-B92F-366F1B126E61}.Release|Any CPU.Build.0 = Release|Any CPU
10373+
{8EB0B983-8851-4565-B92F-366F1B126E61}.Release|arm64.ActiveCfg = Release|Any CPU
10374+
{8EB0B983-8851-4565-B92F-366F1B126E61}.Release|arm64.Build.0 = Release|Any CPU
10375+
{8EB0B983-8851-4565-B92F-366F1B126E61}.Release|x64.ActiveCfg = Release|Any CPU
10376+
{8EB0B983-8851-4565-B92F-366F1B126E61}.Release|x64.Build.0 = Release|Any CPU
10377+
{8EB0B983-8851-4565-B92F-366F1B126E61}.Release|x86.ActiveCfg = Release|Any CPU
10378+
{8EB0B983-8851-4565-B92F-366F1B126E61}.Release|x86.Build.0 = Release|Any CPU
1033910379
EndGlobalSection
1034010380
GlobalSection(SolutionProperties) = preSolution
1034110381
HideSolutionNode = FALSE
@@ -11186,6 +11226,8 @@ Global
1118611226
{5244BC49-2568-4701-80A6-EAB8950AB5FA} = {31854B06-DC6B-4416-97C3-559CC390B8B4}
1118711227
{6F1B115C-1903-40CB-837D-7961AB610F4E} = {5E46DC83-C39C-4E3A-B242-C064607F4367}
1118811228
{56DFE643-7F0F-40C8-9F7F-8EA5357781EF} = {3CBC4802-E9B8-48B7-BC8C-B0AFB9EEC643}
11229+
{E0BE6B86-F8DB-405D-AC05-78C8C9D3857D} = {C3722C5D-E159-4AB3-AF60-769185B31B47}
11230+
{8EB0B983-8851-4565-B92F-366F1B126E61} = {C3722C5D-E159-4AB3-AF60-769185B31B47}
1118911231
EndGlobalSection
1119011232
GlobalSection(ExtensibilityGlobals) = postSolution
1119111233
SolutionGuid = {3E8720B3-DBDD-498C-B383-2CC32A054E8F}

src/Hosting/Server.IntegrationTesting/src/Deployers/SelfHostDeployer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public override async Task<DeploymentResult> DeployAsync()
150150
HostProcess.EnableRaisingEvents = true;
151151
HostProcess.OutputDataReceived += (sender, dataArgs) =>
152152
{
153-
if (string.Equals(dataArgs.Data, ApplicationStartedMessage))
153+
if (!string.IsNullOrEmpty(dataArgs.Data) && dataArgs.Data.Contains(ApplicationStartedMessage))
154154
{
155155
started.TrySetResult();
156156
}

src/Servers/HttpSys/HttpSysServer.slnf

+2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
"src\\Servers\\HttpSys\\samples\\TestClient\\TestClient.csproj",
3232
"src\\Servers\\HttpSys\\src\\Microsoft.AspNetCore.Server.HttpSys.csproj",
3333
"src\\Servers\\HttpSys\\test\\FunctionalTests\\Microsoft.AspNetCore.Server.HttpSys.FunctionalTests.csproj",
34+
"src\\Servers\\HttpSys\\test\\NonHelixTests\\Microsoft.AspNetCore.Server.HttpSys.NonHelixTests.csproj",
3435
"src\\Servers\\HttpSys\\test\\Tests\\Microsoft.AspNetCore.Server.HttpSys.Tests.csproj",
36+
"src\\Servers\\HttpSys\\test\\testassets\\DelegationSite\\DelegationSite.csproj",
3537
"src\\Servers\\IIS\\IISIntegration\\src\\Microsoft.AspNetCore.Server.IISIntegration.csproj",
3638
"src\\Servers\\IIS\\IIS\\src\\Microsoft.AspNetCore.Server.IIS.csproj",
3739
"src\\Servers\\Kestrel\\Core\\src\\Microsoft.AspNetCore.Server.Kestrel.Core.csproj",

src/Servers/HttpSys/src/MessagePump.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public MessagePump(IOptions<HttpSysOptions> options, ILoggerFactory loggerFactor
5555
_serverAddresses = new ServerAddressesFeature();
5656
Features.Set<IServerAddressesFeature>(_serverAddresses);
5757

58-
if (HttpApi.IsFeatureSupported(HttpApiTypes.HTTP_FEATURE_ID.HttpFeatureDelegateEx))
58+
if (HttpApi.SupportsDelegation)
5959
{
6060
var delegationProperty = new ServerDelegationPropertyFeature(Listener.RequestQueue, _logger);
6161
Features.Set<IServerDelegationFeature>(delegationProperty);

src/Servers/HttpSys/src/Microsoft.AspNetCore.Server.HttpSys.csproj

+5
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@
2828
<Reference Include="Microsoft.Net.Http.Headers" />
2929
</ItemGroup>
3030

31+
<ItemGroup>
32+
<InternalsVisibleTo Include="Microsoft.AspNetCore.Server.HttpSys.FunctionalTests" />
33+
<InternalsVisibleTo Include="Microsoft.AspNetCore.Server.HttpSys.NonHelixTests" />
34+
</ItemGroup>
35+
3136
</Project>

src/Servers/HttpSys/src/NativeInterop/HttpApi.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ internal static HTTP_API_VERSION ApiVersion
125125
internal static bool SupportsTrailers { get; private set; }
126126
[MemberNotNullWhen(true, nameof(HttpSetRequestProperty))]
127127
internal static bool SupportsReset { get; private set; }
128+
internal static bool SupportsDelegation { get; private set; }
128129

129130
static HttpApi()
130131
{
@@ -136,18 +137,17 @@ private static void InitHttpApi(ushort majorVersion, ushort minorVersion)
136137
version.HttpApiMajorVersion = majorVersion;
137138
version.HttpApiMinorVersion = minorVersion;
138139

139-
var statusCode = HttpInitialize(version, (uint)HTTP_FLAGS.HTTP_INITIALIZE_SERVER, null);
140+
var statusCode = HttpInitialize(version, (uint)(HTTP_FLAGS.HTTP_INITIALIZE_SERVER | HTTP_FLAGS.HTTP_INITIALIZE_CONFIG), null);
140141

141142
supported = statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS;
142143

143144
if (supported)
144145
{
145146
HttpApiModule = SafeLibraryHandle.Open(HTTPAPI);
146147
HttpSetRequestProperty = HttpApiModule.GetProcAddress<HttpSetRequestPropertyInvoker>("HttpSetRequestProperty", throwIfNotFound: false);
147-
148148
SupportsReset = HttpSetRequestProperty != null;
149-
// Trailers support was added in the same release as Reset, but there's no method we can export to check it directly.
150-
SupportsTrailers = SupportsReset;
149+
SupportsTrailers = IsFeatureSupported(HTTP_FEATURE_ID.HttpFeatureResponseTrailers);
150+
SupportsDelegation = IsFeatureSupported(HTTP_FEATURE_ID.HttpFeatureDelegateEx);
151151
}
152152
}
153153

@@ -160,7 +160,7 @@ internal static bool Supported
160160
}
161161
}
162162

163-
internal static bool IsFeatureSupported(HTTP_FEATURE_ID feature)
163+
private static bool IsFeatureSupported(HTTP_FEATURE_ID feature)
164164
{
165165
try
166166
{

src/Servers/HttpSys/src/Properties/AssemblyInfo.cs

-6
This file was deleted.

src/Servers/HttpSys/src/StandardFeatureCollection.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static StandardFeatureCollection()
4848
_featureFuncLookup[typeof(ITlsHandshakeFeature)] = ctx => ctx.GetTlsHandshakeFeature();
4949
}
5050

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

4-
using System;
5-
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading.Tasks;
94
using Microsoft.AspNetCore.Testing;
10-
using static Microsoft.AspNetCore.HttpSys.Internal.HttpApiTypes;
115

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

20-
private readonly Lazy<bool> _isDelegateSupported = new Lazy<bool>(CanDelegate);
21-
public bool IsMet => (_isDelegateSupported.Value == _isSupported);
14+
public bool IsMet => HttpApi.SupportsDelegation == _isSupported;
2215

2316
public string SkipReason => $"Http.Sys does {(_isSupported ? "not" : "")} support delegating requests";
24-
25-
private static bool CanDelegate()
26-
{
27-
return HttpApi.IsFeatureSupported(HTTP_FEATURE_ID.HttpFeatureDelegateEx);
28-
}
2917
}
3018
}

src/Servers/HttpSys/test/FunctionalTests/DelegateTests.cs

+3
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ public async Task DelegateAfterRequestBodyReadShouldThrow()
148148
[DelegateSupportedCondition(false)]
149149
public async Task DelegationFeaturesAreNull()
150150
{
151+
// Testing the DelegateSupportedCondition
152+
Assert.True(Environment.OSVersion.Version < new Version(10, 0, 22000), "This should be supported on Win 11.");
153+
151154
using var delegator = Utilities.CreateHttpServer(out var delegatorAddress, httpContext =>
152155
{
153156
var delegateFeature = httpContext.Features.Get<IHttpSysRequestDelegationFeature>();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Net.Http;
5+
using Microsoft.AspNetCore.Server.IntegrationTesting;
6+
using Microsoft.AspNetCore.Testing;
7+
using Xunit.Abstractions;
8+
9+
namespace Microsoft.AspNetCore.Server.HttpSys.NonHelixTests
10+
{
11+
public class DelegateOutOfProcTests : LoggedTest
12+
{
13+
public DelegateOutOfProcTests(ITestOutputHelper output) : base(output) { }
14+
15+
[ConditionalFact]
16+
[DelegateSupportedCondition(true)]
17+
public async Task CanDelegateOutOfProcess()
18+
{
19+
using var _ = StartLog(out var loggerFactory);
20+
21+
var logger = loggerFactory.CreateLogger("CanDelegateOutOfProcess");
22+
23+
// https://github.com/dotnet/aspnetcore/issues/8247
24+
#pragma warning disable 0618
25+
var applicationPath = Path.Combine(TestPathUtilities.GetSolutionRootDirectory("HttpSysServer"), "test", "testassets",
26+
"DelegationSite");
27+
#pragma warning restore 0618
28+
29+
var deploymentParameters = new DeploymentParameters(
30+
applicationPath,
31+
ServerType.HttpSys,
32+
RuntimeFlavor.CoreClr,
33+
RuntimeArchitecture.x64)
34+
{
35+
EnvironmentName = "Testing",
36+
TargetFramework = Tfm.Default,
37+
ApplicationType = ApplicationType.Portable,
38+
PublishApplicationBeforeDeployment = true,
39+
StatusMessagesEnabled = true
40+
};
41+
42+
var queueName = Guid.NewGuid().ToString();
43+
deploymentParameters.EnvironmentVariables["queue"] = queueName;
44+
45+
using var deployer = new SelfHostDeployer(deploymentParameters, loggerFactory);
46+
var deploymentResult = await deployer.DeployAsync().DefaultTimeout();
47+
48+
// Make sure the deployment really worked
49+
var responseString = await deploymentResult.HttpClient.GetStringAsync("").DefaultTimeout();
50+
Assert.Equal("Hello from delegatee", responseString);
51+
52+
DelegationRule destination = default;
53+
using var delegator = Utilities.CreateHttpServer(out var delegatorAddress, httpContext =>
54+
{
55+
var delegateFeature = httpContext.Features.Get<IHttpSysRequestDelegationFeature>();
56+
delegateFeature.DelegateRequest(destination);
57+
return Task.CompletedTask;
58+
});
59+
60+
var delegationProperty = delegator.Features.Get<IServerDelegationFeature>();
61+
using (destination = delegationProperty.CreateDelegationRule(queueName, deploymentResult.ApplicationBaseUri))
62+
{
63+
// Send a request to the delegator that gets transfered to the delegatee in the other process.
64+
using var client = new HttpClient();
65+
responseString = await client.GetStringAsync(delegatorAddress).DefaultTimeout();
66+
Assert.Equal("Hello from delegatee", responseString);
67+
}
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)