From 11025b894e5bfc39ffabb854ca0a33663cdf0cc8 Mon Sep 17 00:00:00 2001 From: John Luo Date: Fri, 8 Jan 2016 10:52:51 -0800 Subject: [PATCH] Updating to new options pattern --- .../AuthenticationHandler.cs | 1 + .../IISPlatformHandlerMiddleware.cs | 8 +++-- .../IISPlatformHandlerMiddlewareExtensions.cs | 29 ++----------------- .../IISPlatformHandlerOptions.cs | 3 +- .../project.json | 3 +- .../HttpPlatformHandlerMiddlewareTests.cs | 5 +++- 6 files changed, 17 insertions(+), 32 deletions(-) diff --git a/src/Microsoft.AspNet.IISPlatformHandler/AuthenticationHandler.cs b/src/Microsoft.AspNet.IISPlatformHandler/AuthenticationHandler.cs index e7f44de189..9526f6635b 100644 --- a/src/Microsoft.AspNet.IISPlatformHandler/AuthenticationHandler.cs +++ b/src/Microsoft.AspNet.IISPlatformHandler/AuthenticationHandler.cs @@ -5,6 +5,7 @@ using System; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.Http.Features.Authentication; diff --git a/src/Microsoft.AspNet.IISPlatformHandler/IISPlatformHandlerMiddleware.cs b/src/Microsoft.AspNet.IISPlatformHandler/IISPlatformHandlerMiddleware.cs index 19b530983d..f99a701ded 100644 --- a/src/Microsoft.AspNet.IISPlatformHandler/IISPlatformHandlerMiddleware.cs +++ b/src/Microsoft.AspNet.IISPlatformHandler/IISPlatformHandlerMiddleware.cs @@ -5,11 +5,12 @@ using System; using System.Globalization; using System.Security.Principal; using System.Threading.Tasks; +using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features.Authentication; using Microsoft.AspNet.Http.Features.Authentication.Internal; using Microsoft.Extensions.Internal; +using Microsoft.Extensions.Options; using Microsoft.Extensions.Primitives; namespace Microsoft.AspNet.IISPlatformHandler @@ -21,7 +22,7 @@ namespace Microsoft.AspNet.IISPlatformHandler private readonly RequestDelegate _next; private readonly IISPlatformHandlerOptions _options; - public IISPlatformHandlerMiddleware(RequestDelegate next, IISPlatformHandlerOptions options) + public IISPlatformHandlerMiddleware(RequestDelegate next, IOptions options) { if (next == null) { @@ -31,8 +32,9 @@ namespace Microsoft.AspNet.IISPlatformHandler { throw new ArgumentNullException(nameof(options)); } + _next = next; - _options = options; + _options = options.Value; } public async Task Invoke(HttpContext httpContext) diff --git a/src/Microsoft.AspNet.IISPlatformHandler/IISPlatformHandlerMiddlewareExtensions.cs b/src/Microsoft.AspNet.IISPlatformHandler/IISPlatformHandlerMiddlewareExtensions.cs index 88b0b67041..0fd8b5f428 100644 --- a/src/Microsoft.AspNet.IISPlatformHandler/IISPlatformHandlerMiddlewareExtensions.cs +++ b/src/Microsoft.AspNet.IISPlatformHandler/IISPlatformHandlerMiddlewareExtensions.cs @@ -3,6 +3,7 @@ using System; using Microsoft.AspNet.IISPlatformHandler; +using Microsoft.Extensions.Options; namespace Microsoft.AspNet.Builder { @@ -21,31 +22,7 @@ namespace Microsoft.AspNet.Builder throw new ArgumentNullException(nameof(app)); } - return app.UseIISPlatformHandler(options => { }); - } - - /// - /// Adds middleware for interacting with the IIS HttpPlatformHandler reverse proxy module. - /// This will handle forwarded Windows Authentication, request scheme, remote IPs, etc.. - /// - /// - /// - /// - public static IApplicationBuilder UseIISPlatformHandler(this IApplicationBuilder app, Action configureOptions) - { - if (app == null) - { - throw new ArgumentNullException(nameof(app)); - } - if (configureOptions == null) - { - throw new ArgumentNullException(nameof(configureOptions)); - } - - var options = new IISPlatformHandlerOptions(); - configureOptions(options); - - return app.UseMiddleware(options); + return app.UseMiddleware(); } /// @@ -66,7 +43,7 @@ namespace Microsoft.AspNet.Builder throw new ArgumentNullException(nameof(options)); } - return app.UseMiddleware(options); + return app.UseMiddleware(Options.Create(options)); } } } diff --git a/src/Microsoft.AspNet.IISPlatformHandler/IISPlatformHandlerOptions.cs b/src/Microsoft.AspNet.IISPlatformHandler/IISPlatformHandlerOptions.cs index ec19cef211..9d4a4e12e2 100644 --- a/src/Microsoft.AspNet.IISPlatformHandler/IISPlatformHandlerOptions.cs +++ b/src/Microsoft.AspNet.IISPlatformHandler/IISPlatformHandlerOptions.cs @@ -3,8 +3,9 @@ using System.Collections.Generic; using Microsoft.AspNet.Http.Authentication; +using Microsoft.AspNet.IISPlatformHandler; -namespace Microsoft.AspNet.IISPlatformHandler +namespace Microsoft.AspNet.Builder { public class IISPlatformHandlerOptions { diff --git a/src/Microsoft.AspNet.IISPlatformHandler/project.json b/src/Microsoft.AspNet.IISPlatformHandler/project.json index 6bf217cd0c..e00f2aa8e2 100644 --- a/src/Microsoft.AspNet.IISPlatformHandler/project.json +++ b/src/Microsoft.AspNet.IISPlatformHandler/project.json @@ -15,7 +15,8 @@ "Microsoft.Extensions.SecurityHelper.Sources": { "type": "build", "version": "1.0.0-*" - } + }, + "Microsoft.Extensions.Options": "1.0.0-*" }, "frameworks": { "net451": { }, diff --git a/test/Microsoft.AspNet.IISPlatformHandler.Tests/HttpPlatformHandlerMiddlewareTests.cs b/test/Microsoft.AspNet.IISPlatformHandler.Tests/HttpPlatformHandlerMiddlewareTests.cs index c522fb6901..9ae4ce94ec 100644 --- a/test/Microsoft.AspNet.IISPlatformHandler.Tests/HttpPlatformHandlerMiddlewareTests.cs +++ b/test/Microsoft.AspNet.IISPlatformHandler.Tests/HttpPlatformHandlerMiddlewareTests.cs @@ -47,7 +47,10 @@ namespace Microsoft.AspNet.IISPlatformHandler var builder = new WebApplicationBuilder() .Configure(app => { - app.UseIISPlatformHandler(options => options.FlowWindowsAuthentication = false); + app.UseIISPlatformHandler(new IISPlatformHandlerOptions + { + FlowWindowsAuthentication = false + }); app.Run(context => { var auth = (IHttpAuthenticationFeature)context.Features[typeof(IHttpAuthenticationFeature)];