Skip to content

Commit d7fc06a

Browse files
authored
Move IServerVariablesFeature to Http.Features (#11007)
1 parent 5561338 commit d7fc06a

16 files changed

+104
-46
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
@@ -9,6 +9,10 @@ public static void AppendList<T>(this Microsoft.AspNetCore.Http.IHeaderDictionar
99
public static Microsoft.AspNetCore.Http.Headers.RequestHeaders GetTypedHeaders(this Microsoft.AspNetCore.Http.HttpRequest request) { throw null; }
1010
public static Microsoft.AspNetCore.Http.Headers.ResponseHeaders GetTypedHeaders(this Microsoft.AspNetCore.Http.HttpResponse response) { throw null; }
1111
}
12+
public static partial class HttpContextServerVariableExtensions
13+
{
14+
public static string GetServerVariable(this Microsoft.AspNetCore.Http.HttpContext context, string variableName) { throw null; }
15+
}
1216
public static partial class ResponseExtensions
1317
{
1418
public static void Clear(this Microsoft.AspNetCore.Http.HttpResponse response) { }
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 HttpContextServerVariableExtensions
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
@@ -260,6 +260,10 @@ public partial interface IResponseCookiesFeature
260260
{
261261
Microsoft.AspNetCore.Http.IResponseCookies Cookies { get; }
262262
}
263+
public partial interface IServerVariablesFeature
264+
{
265+
string this[string variableName] { get; set; }
266+
}
263267
public partial interface IServiceProvidersFeature
264268
{
265269
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/samples/NativeIISSample/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void Configure(IApplicationBuilder app)
8080

8181
foreach (var varName in IISServerVarNames)
8282
{
83-
await context.Response.WriteAsync(varName + ": " + context.GetIISServerVariable(varName) + Environment.NewLine);
83+
await context.Response.WriteAsync(varName + ": " + context.GetServerVariable(varName) + Environment.NewLine);
8484
}
8585

8686
await context.Response.WriteAsync(Environment.NewLine);

0 commit comments

Comments
 (0)