diff --git a/samples/RewriteSample/Startup.cs b/samples/RewriteSample/Startup.cs index 6a76d5df3e..b4bfa3c977 100644 --- a/samples/RewriteSample/Startup.cs +++ b/samples/RewriteSample/Startup.cs @@ -11,14 +11,14 @@ namespace RewriteSample { public class Startup { - public void Configure(IApplicationBuilder app, IHostingEnvironment hostingEnvironment) + public void Configure(IApplicationBuilder app, IHostingEnvironment env) { var options = new RewriteOptions() .AddRedirect("(.*)/$", "$1") .AddRewrite(@"app/(\d+)", "app?id=$1") .AddRedirectToHttps(302) - .AddIISUrlRewrite(hostingEnvironment, "UrlRewrite.xml") - .AddApacheModRewrite(hostingEnvironment, "Rewrite.txt"); + .AddIISUrlRewrite(env.ContentRootFileProvider, "UrlRewrite.xml") + .AddApacheModRewrite(env.ContentRootFileProvider, "Rewrite.txt"); app.UseRewriter(options); diff --git a/src/Microsoft.AspNetCore.Rewrite/ApacheModRewriteOptionsExtensions.cs b/src/Microsoft.AspNetCore.Rewrite/ApacheModRewriteOptionsExtensions.cs index 99aa31ada4..b4779aece7 100644 --- a/src/Microsoft.AspNetCore.Rewrite/ApacheModRewriteOptionsExtensions.cs +++ b/src/Microsoft.AspNetCore.Rewrite/ApacheModRewriteOptionsExtensions.cs @@ -3,50 +3,45 @@ using System; using System.IO; -using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite; +using Microsoft.Extensions.FileProviders; namespace Microsoft.AspNetCore.Rewrite { /// - /// Apache mod_rewrite extensions on top of the + /// Extensions for adding Apache mod_rewrite rules to /// public static class ApacheModRewriteOptionsExtensions { /// - /// Imports rules from a mod_rewrite file and adds the rules to current rules. + /// Add rules from an Apache mod_rewrite file /// - /// The Rewrite options. - /// The Hosting Environment + /// The + /// The /// The path to the file containing mod_rewrite rules. - public static RewriteOptions AddApacheModRewrite(this RewriteOptions options, IHostingEnvironment hostingEnvironment, string filePath) + public static RewriteOptions AddApacheModRewrite(this RewriteOptions options, IFileProvider fileProvider, string filePath) { if (options == null) { throw new ArgumentNullException(nameof(options)); } - if (hostingEnvironment == null) + if (fileProvider == null) { - throw new ArgumentNullException(nameof(hostingEnvironment)); + throw new ArgumentNullException(nameof(fileProvider)); } - if (string.IsNullOrEmpty(filePath)) - { - throw new ArgumentException(nameof(filePath)); - } - - var path = Path.Combine(hostingEnvironment.ContentRootPath, filePath); - using (var stream = File.OpenRead(path)) + var fileInfo = fileProvider.GetFileInfo(filePath); + using (var stream = fileInfo.CreateReadStream()) { return options.AddApacheModRewrite(new StreamReader(stream)); } } /// - /// Imports rules from a mod_rewrite file and adds the rules to current rules. + /// Add rules from an Apache mod_rewrite file /// - /// The Rewrite options. + /// The /// A stream of mod_rewrite rules. public static RewriteOptions AddApacheModRewrite(this RewriteOptions options, TextReader reader) { diff --git a/src/Microsoft.AspNetCore.Rewrite/Logging/RewriteMiddlewareLoggingExtensions.cs b/src/Microsoft.AspNetCore.Rewrite/Extensions/RewriteMiddlewareLoggingExtensions.cs similarity index 100% rename from src/Microsoft.AspNetCore.Rewrite/Logging/RewriteMiddlewareLoggingExtensions.cs rename to src/Microsoft.AspNetCore.Rewrite/Extensions/RewriteMiddlewareLoggingExtensions.cs diff --git a/src/Microsoft.AspNetCore.Rewrite/IISUrlRewriteOptionsExtensions.cs b/src/Microsoft.AspNetCore.Rewrite/IISUrlRewriteOptionsExtensions.cs index 05d49b9ac8..bed837ae44 100644 --- a/src/Microsoft.AspNetCore.Rewrite/IISUrlRewriteOptionsExtensions.cs +++ b/src/Microsoft.AspNetCore.Rewrite/IISUrlRewriteOptionsExtensions.cs @@ -3,50 +3,46 @@ using System; using System.IO; -using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite; +using Microsoft.Extensions.FileProviders; namespace Microsoft.AspNetCore.Rewrite { /// - /// IIS Url rewrite extensions on top of the + /// Extensions for adding IIS Url Rewrite rules to /// public static class IISUrlRewriteOptionsExtensions { /// - /// Imports rules from a mod_rewrite file and adds the rules to current rules. + /// Add rules from a IIS config file containing Url Rewrite rules /// - /// The UrlRewrite options. - /// - /// The path to the file containing urlrewrite rules. - public static RewriteOptions AddIISUrlRewrite(this RewriteOptions options, IHostingEnvironment hostingEnvironment, string filePath) + /// The + /// The + /// The path to the file containing UrlRewrite rules. + public static RewriteOptions AddIISUrlRewrite(this RewriteOptions options, IFileProvider fileProvider, string filePath) { if (options == null) { throw new ArgumentNullException(nameof(options)); } - if (hostingEnvironment == null) + if (fileProvider == null) { - throw new ArgumentNullException(nameof(hostingEnvironment)); + throw new ArgumentNullException(nameof(fileProvider)); } - if (string.IsNullOrEmpty(filePath)) - { - throw new ArgumentException(nameof(filePath)); - } + var file = fileProvider.GetFileInfo(filePath); - var path = Path.Combine(hostingEnvironment.ContentRootPath, filePath); - using (var stream = File.OpenRead(path)) + using (var stream = file.CreateReadStream()) { return AddIISUrlRewrite(options, new StreamReader(stream)); } } /// - /// Imports rules from a mod_rewrite file and adds the rules to current rules. + /// Add rules from a IIS config file containing Url Rewrite rules /// - /// The UrlRewrite options. + /// The /// The text reader stream. public static RewriteOptions AddIISUrlRewrite(this RewriteOptions options, TextReader reader) { @@ -66,6 +62,7 @@ namespace Microsoft.AspNetCore.Rewrite { options.Rules.Add(rule); } + return options; } } diff --git a/src/Microsoft.AspNetCore.Rewrite/RewriteBuilderExtensions.cs b/src/Microsoft.AspNetCore.Rewrite/RewriteBuilderExtensions.cs index 88d7676c30..724dccf3d1 100644 --- a/src/Microsoft.AspNetCore.Rewrite/RewriteBuilderExtensions.cs +++ b/src/Microsoft.AspNetCore.Rewrite/RewriteBuilderExtensions.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Builder /// /// Checks if a given Url matches rules and conditions, and modifies the HttpContext on match. /// - /// + /// The /// Options for rewrite. /// public static IApplicationBuilder UseRewriter(this IApplicationBuilder app, RewriteOptions options) diff --git a/src/Microsoft.AspNetCore.Rewrite/RewriteMiddleware.cs b/src/Microsoft.AspNetCore.Rewrite/RewriteMiddleware.cs index 7838ecbc0a..9f3802d395 100644 --- a/src/Microsoft.AspNetCore.Rewrite/RewriteMiddleware.cs +++ b/src/Microsoft.AspNetCore.Rewrite/RewriteMiddleware.cs @@ -14,7 +14,7 @@ using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Rewrite { /// - /// Represents a middleware that rewrites urls imported from mod_rewrite, UrlRewrite, and code. + /// Represents a middleware that rewrites urls /// public class RewriteMiddleware { diff --git a/src/Microsoft.AspNetCore.Rewrite/RewriteOptions.cs b/src/Microsoft.AspNetCore.Rewrite/RewriteOptions.cs index f4370cabb4..8e51c78071 100644 --- a/src/Microsoft.AspNetCore.Rewrite/RewriteOptions.cs +++ b/src/Microsoft.AspNetCore.Rewrite/RewriteOptions.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Microsoft.Extensions.FileProviders; +using Microsoft.AspNetCore.Hosting; namespace Microsoft.AspNetCore.Rewrite { @@ -17,7 +18,7 @@ namespace Microsoft.AspNetCore.Rewrite public IList Rules { get; } = new List(); /// - /// Gets and sets the File Provider for file and directory checks. + /// Gets and sets the File Provider for file and directory checks. Defaults to /// public IFileProvider StaticFileProvider { get; set; } } diff --git a/src/Microsoft.AspNetCore.Rewrite/RewriteOptionsExtensions.cs b/src/Microsoft.AspNetCore.Rewrite/RewriteOptionsExtensions.cs index 906c107952..5b9eec9e88 100644 --- a/src/Microsoft.AspNetCore.Rewrite/RewriteOptionsExtensions.cs +++ b/src/Microsoft.AspNetCore.Rewrite/RewriteOptionsExtensions.cs @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Rewrite /// /// Adds a rule to the current rules. /// - /// The UrlRewrite options. + /// The . /// A rule to be added to the current rules. /// The Rewrite options. public static RewriteOptions Add(this RewriteOptions options, Rule rule) @@ -26,7 +26,7 @@ namespace Microsoft.AspNetCore.Rewrite /// /// Adds a rule to the current rules. /// - /// The Rewrite options. + /// The . /// A Func that checks and applies the rule. /// public static RewriteOptions Add(this RewriteOptions options, Action applyRule) @@ -38,7 +38,7 @@ namespace Microsoft.AspNetCore.Rewrite /// /// Rewrites the path if the regex matches the HttpContext's PathString /// - /// The Rewrite options. + /// The . /// The regex string to compare with. /// If the regex matches, what to replace HttpContext with. /// The Rewrite options. @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Rewrite /// /// Rewrites the path if the regex matches the HttpContext's PathString /// - /// The Rewrite options. + /// The . /// The regex string to compare with. /// If the regex matches, what to replace the uri with. /// If the regex matches, conditionally stop processing other rules. @@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.Rewrite /// /// Redirect the request if the regex matches the HttpContext's PathString /// - /// The Rewrite options. + /// The . /// The regex string to compare with. /// If the regex matches, what to replace the uri with. /// The Rewrite options. @@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.Rewrite /// /// Redirect the request if the regex matches the HttpContext's PathString /// - /// The Rewrite options. + /// The . /// The regex string to compare with. /// If the regex matches, what to replace the uri with. /// The status code to add to the response. @@ -91,7 +91,7 @@ namespace Microsoft.AspNetCore.Rewrite /// Redirect a request to https if the incoming request is http, with returning a 301 /// status code for permanently redirected. /// - /// + /// The . /// public static RewriteOptions AddRedirectToHttpsPermanent(this RewriteOptions options) { @@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.Rewrite /// /// Redirect a request to https if the incoming request is http /// - /// The Rewrite options. + /// The . public static RewriteOptions AddRedirectToHttps(this RewriteOptions options) { return AddRedirectToHttps(options, statusCode: 302, sslPort: null); @@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.Rewrite /// /// Redirect a request to https if the incoming request is http /// - /// The Rewrite options. + /// The . /// The status code to add to the response. public static RewriteOptions AddRedirectToHttps(this RewriteOptions options, int statusCode) { @@ -120,7 +120,7 @@ namespace Microsoft.AspNetCore.Rewrite /// /// Redirect a request to https if the incoming request is http /// - /// The Rewrite options. + /// The . /// The status code to add to the response. /// The SSL port to add to the response. public static RewriteOptions AddRedirectToHttps(this RewriteOptions options, int statusCode, int? sslPort) diff --git a/src/Microsoft.AspNetCore.Rewrite/Rule.cs b/src/Microsoft.AspNetCore.Rewrite/Rule.cs index 22b5a253e0..b86d0e454d 100644 --- a/src/Microsoft.AspNetCore.Rewrite/Rule.cs +++ b/src/Microsoft.AspNetCore.Rewrite/Rule.cs @@ -10,8 +10,8 @@ namespace Microsoft.AspNetCore.Rewrite { /// /// Applies the rule. - /// Implementations of ApplyRule should set the value for RewriteContext.Results - /// (defaults to RuleTermination.Continue) + /// Implementations of ApplyRule should set the value for + /// (defaults to ) /// /// public abstract void ApplyRule(RewriteContext context);