Skip to content

Commit 31eeab5

Browse files
committed
Move IServerVariablesFeature to Http.Features
1 parent e953537 commit 31eeab5

12 files changed

+55
-34
lines changed

src/Http/Http.Extensions/ref/Microsoft.AspNetCore.Http.Extensions.netcoreapp3.0.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
namespace Microsoft.AspNetCore.Http
55
{
6+
public static partial class ContextExtensions
7+
{
8+
public static string GetServerVariable(this Microsoft.AspNetCore.Http.HttpContext context, string variableName) { throw null; }
9+
}
610
public static partial class HeaderDictionaryTypeExtensions
711
{
812
public static void AppendList<T>(this Microsoft.AspNetCore.Http.IHeaderDictionary Headers, string name, System.Collections.Generic.IList<T> values) { }
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNetCore.Http.Features;
5+
6+
namespace Microsoft.AspNetCore.Http
7+
{
8+
public static class ContextExtensions
9+
{
10+
/// <summary>
11+
/// Gets the value of a server variable for the current request.
12+
/// </summary>
13+
/// <param name="context">The http context for the request.</param>
14+
/// <param name="variableName">The name of the variable.</param>
15+
/// <returns>
16+
/// <c>null</c> if the server does not support the <see cref="IServerVariablesFeature"/> feature.
17+
/// May return null or empty if the variable does not exist or is not set.
18+
/// </returns>
19+
public static string GetServerVariable(this HttpContext context, string variableName)
20+
{
21+
var feature = context.Features.Get<IServerVariablesFeature>();
22+
23+
if (feature == null)
24+
{
25+
return null;
26+
}
27+
28+
return feature[variableName];
29+
}
30+
}
31+
}

src/Http/Http.Features/ref/Microsoft.AspNetCore.Http.Features.netstandard2.0.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ public partial interface IResponseCookiesFeature
255255
{
256256
Microsoft.AspNetCore.Http.IResponseCookies Cookies { get; }
257257
}
258+
public partial interface IServerVariablesFeature
259+
{
260+
string this[string variableName] { get; set; }
261+
}
258262
public partial interface IServiceProvidersFeature
259263
{
260264
System.IServiceProvider RequestServices { get; set; }

src/Servers/IIS/IIS/src/IServerVariableFeature.cs renamed to src/Http/Http.Features/src/IServerVariablesFeature.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ namespace Microsoft.AspNetCore.Http.Features
55
{
66
/// <summary>
77
/// This feature provides access to request server variables set.
8-
/// <para>
9-
/// This feature is only available when hosting ASP.NET Core in-process with IIS or IIS Express.
10-
/// </para>
118
/// </summary>
12-
/// <remarks>
13-
/// For a list of common server variables available in IIS, see http://go.microsoft.com/fwlink/?LinkId=52471.
14-
/// </remarks>
159
public interface IServerVariablesFeature
1610
{
1711
/// <summary>

src/Middleware/Rewrite/ref/Microsoft.AspNetCore.Rewrite.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<Compile Include="Microsoft.AspNetCore.Rewrite.netcoreapp3.0.cs" />
88
<Reference Include="Microsoft.AspNetCore.Hosting.Abstractions" />
99
<Reference Include="Microsoft.AspNetCore.Http.Extensions" />
10-
<Reference Include="Microsoft.AspNetCore.Server.IIS" />
1110
<Reference Include="Microsoft.Extensions.Configuration.Abstractions" />
1211
<Reference Include="Microsoft.Extensions.FileProviders.Abstractions" />
1312
<Reference Include="Microsoft.Extensions.Logging.Abstractions" />

src/Middleware/Rewrite/src/Internal/PatternSegments/IISServerVariableSegment.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using Microsoft.AspNetCore.Server.IIS;
5+
using Microsoft.AspNetCore.Http;
66

77
namespace Microsoft.AspNetCore.Rewrite.Internal.PatternSegments
88
{
@@ -19,7 +19,7 @@ public IISServerVariableSegment(string variableName, Func<PatternSegment> fallba
1919

2020
public override string Evaluate(RewriteContext context, BackReferenceCollection ruleBackReferences, BackReferenceCollection conditionBackReferences)
2121
{
22-
return context.HttpContext.GetIISServerVariable(_variableName) ?? _fallbackThunk().Evaluate(context, ruleBackReferences, conditionBackReferences);
22+
return context.HttpContext.GetServerVariable(_variableName) ?? _fallbackThunk().Evaluate(context, ruleBackReferences, conditionBackReferences);
2323
}
2424
}
2525
}

src/Middleware/Rewrite/src/Microsoft.AspNetCore.Rewrite.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<Description>ASP.NET Core basic middleware for rewriting URLs. Includes:
@@ -15,7 +15,6 @@
1515
<ItemGroup>
1616
<Reference Include="Microsoft.AspNetCore.Hosting.Abstractions" />
1717
<Reference Include="Microsoft.AspNetCore.Http.Extensions" />
18-
<Reference Include="Microsoft.AspNetCore.Server.IIS" />
1918
<Reference Include="Microsoft.Extensions.Configuration.Abstractions" />
2019
<Reference Include="Microsoft.Extensions.FileProviders.Abstractions" />
2120
<Reference Include="Microsoft.Extensions.Logging.Abstractions" />

src/Servers/IIS/IIS/ref/Microsoft.AspNetCore.Server.IIS.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<Reference Include="Microsoft.AspNetCore.Authentication.Core" />
99
<Reference Include="Microsoft.AspNetCore.Connections.Abstractions" />
1010
<Reference Include="Microsoft.AspNetCore.Hosting.Abstractions" />
11+
<Reference Include="Microsoft.AspNetCore.Http.Extensions" />
12+
<Reference Include="Microsoft.AspNetCore.Http.Features" />
1113
<Reference Include="Microsoft.Extensions.FileProviders.Physical" />
1214
<Reference Include="Microsoft.Extensions.TypeNameHelper.Sources" />
1315
<Reference Include="System.IO.Pipelines" />

src/Servers/IIS/IIS/ref/Microsoft.AspNetCore.Server.IIS.netcoreapp3.0.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ public static partial class WebHostBuilderIISExtensions
1919
public static Microsoft.AspNetCore.Hosting.IWebHostBuilder UseIIS(this Microsoft.AspNetCore.Hosting.IWebHostBuilder hostBuilder) { throw null; }
2020
}
2121
}
22-
namespace Microsoft.AspNetCore.Http.Features
23-
{
24-
public partial interface IServerVariablesFeature
25-
{
26-
string this[string variableName] { get; set; }
27-
}
28-
}
2922
namespace Microsoft.AspNetCore.Server.IIS
3023
{
3124
public sealed partial class BadHttpRequestException : System.IO.IOException
@@ -35,6 +28,7 @@ internal BadHttpRequestException() { }
3528
}
3629
public static partial class HttpContextExtensions
3730
{
31+
[System.ObsoleteAttribute("This is obsolete and will be removed in a future version. Use GetServerVariable instead.")]
3832
public static string GetIISServerVariable(this Microsoft.AspNetCore.Http.HttpContext context, string variableName) { throw null; }
3933
}
4034
public partial class IISServerDefaults

src/Servers/IIS/IIS/src/AssemblyInfo.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Runtime.CompilerServices;
5+
using Microsoft.AspNetCore.Http.Features;
56

67
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.IISIntegration.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
78
[assembly: InternalsVisibleTo("IIS.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
9+
[assembly: TypeForwardedTo(typeof(IServerVariablesFeature))]
810

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using Microsoft.AspNetCore.Http;
56
using Microsoft.AspNetCore.Http.Features;
67

@@ -17,22 +18,11 @@ public static class HttpContextExtensions
1718
/// <param name="context">The http context for the request.</param>
1819
/// <param name="variableName">The name of the variable.</param>
1920
/// <returns>
20-
/// <c>null</c> if the feature does not support the <see cref="IServerVariablesFeature"/> feature.
21+
/// <c>null</c> if the server does not support the <see cref="IServerVariablesFeature"/> feature.
2122
/// May return null or empty if the variable does not exist or is not set.
2223
/// </returns>
23-
/// <remarks>
24-
/// For a list of common server variables available in IIS, see http://go.microsoft.com/fwlink/?LinkId=52471.
25-
/// </remarks>
26-
public static string GetIISServerVariable(this HttpContext context, string variableName)
27-
{
28-
var feature = context.Features.Get<IServerVariablesFeature>();
29-
30-
if (feature == null)
31-
{
32-
return null;
33-
}
34-
35-
return feature[variableName];
36-
}
24+
[Obsolete("This is obsolete and will be removed in a future version. Use " + nameof(ContextExtensions.GetServerVariable) + " instead.")]
25+
public static string GetIISServerVariable(this HttpContext context, string variableName) =>
26+
context.GetServerVariable(variableName);
3727
}
3828
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.0</TargetFramework>
@@ -35,6 +35,8 @@
3535
<Reference Include="Microsoft.AspNetCore.Authentication.Core" />
3636
<Reference Include="Microsoft.AspNetCore.Connections.Abstractions" />
3737
<Reference Include="Microsoft.AspNetCore.Hosting.Abstractions" />
38+
<Reference Include="Microsoft.AspNetCore.Http.Extensions" />
39+
<Reference Include="Microsoft.AspNetCore.Http.Features" />
3840
<Reference Include="Microsoft.Extensions.FileProviders.Physical" />
3941
<Reference Include="Microsoft.Extensions.TypeNameHelper.Sources" />
4042
<Reference Include="System.IO.Pipelines" />

0 commit comments

Comments
 (0)