Add 'Apache' and 'IIS' to internal namespaces and classes

This commit is contained in:
Nate McMaster 2016-09-06 10:51:19 -07:00
parent 57c1f877e3
commit a5ff9d8003
No known key found for this signature in database
GPG Key ID: 6572615A705669C9
53 changed files with 81 additions and 83 deletions

5
.gitignore vendored
View File

@ -27,4 +27,7 @@ project.lock.json
*.ipch *.ipch
.vs/ .vs/
.build/ .build/
.testPublish/ .testPublish/
.idea/
.vscode/

View File

@ -4,7 +4,7 @@
using System; using System;
using System.IO; using System.IO;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Rewrite.Internal.ModRewrite; using Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite;
namespace Microsoft.AspNetCore.Rewrite namespace Microsoft.AspNetCore.Rewrite
{ {

View File

@ -4,7 +4,7 @@
using System; using System;
using System.IO; using System.IO;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite; using Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite;
namespace Microsoft.AspNetCore.Rewrite namespace Microsoft.AspNetCore.Rewrite
{ {

View File

@ -4,15 +4,15 @@
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Rewrite.Logging; using Microsoft.AspNetCore.Rewrite.Logging;
namespace Microsoft.AspNetCore.Rewrite.Internal namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
{ {
public class ModRewriteRule : Rule public class ApacheModRewriteRule : Rule
{ {
public UrlMatch InitialMatch { get; } public UrlMatch InitialMatch { get; }
public IList<Condition> Conditions { get; } public IList<Condition> Conditions { get; }
public IList<UrlAction> Actions { get; } public IList<UrlAction> Actions { get; }
public ModRewriteRule(UrlMatch initialMatch, IList<Condition> conditions, IList<UrlAction> urlActions) public ApacheModRewriteRule(UrlMatch initialMatch, IList<Condition> conditions, IList<UrlAction> urlActions)
{ {
Conditions = conditions; Conditions = conditions;
InitialMatch = initialMatch; InitialMatch = initialMatch;

View File

@ -3,7 +3,7 @@
using System; using System;
namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
{ {
/// <summary> /// <summary>
/// Parses the "CondPattern" portion of the RewriteCond. /// Parses the "CondPattern" portion of the RewriteCond.

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
{ {
public enum ConditionType public enum ConditionType
{ {

View File

@ -5,7 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
{ {
public class FileParser public class FileParser
{ {

View File

@ -4,7 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
{ {
public class FlagParser public class FlagParser
{ {

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
{ {
public enum FlagType public enum FlagType
{ {

View File

@ -3,7 +3,7 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
{ {
// For more information of flags, and what flags we currently support: // For more information of flags, and what flags we currently support:
// https://github.com/aspnet/BasicMiddleware/issues/66 // https://github.com/aspnet/BasicMiddleware/issues/66

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
{ {
public enum OperationType public enum OperationType
{ {

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
{ {
public class ParsedModRewriteInput public class ParsedModRewriteInput
{ {

View File

@ -7,7 +7,7 @@ using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Rewrite.Internal.UrlActions; using Microsoft.AspNetCore.Rewrite.Internal.UrlActions;
using Microsoft.AspNetCore.Rewrite.Internal.UrlMatches; using Microsoft.AspNetCore.Rewrite.Internal.UrlMatches;
namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
{ {
public class RuleBuilder public class RuleBuilder
{ {
@ -17,13 +17,13 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite
private readonly TimeSpan RegexTimeout = TimeSpan.FromMilliseconds(1); private readonly TimeSpan RegexTimeout = TimeSpan.FromMilliseconds(1);
public ModRewriteRule Build() public ApacheModRewriteRule Build()
{ {
if (_actions.Count == 0 || _match == null) if (_actions.Count == 0 || _match == null)
{ {
throw new InvalidOperationException("Cannot create ModRewriteRule without action and match"); throw new InvalidOperationException("Cannot create ModRewriteRule without action and match");
} }
return new ModRewriteRule(_match, _conditions, _actions); return new ApacheModRewriteRule(_match, _conditions, _actions);
} }
public void AddRule(string rule) public void AddRule(string rule)

View File

@ -3,7 +3,7 @@
using System; using System;
namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
{ {
public class RuleRegexParser public class RuleRegexParser
{ {

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
{ {
public enum SegmentType public enum SegmentType
{ {

View File

@ -5,7 +5,7 @@ using System;
using Microsoft.AspNetCore.Rewrite.Internal.PatternSegments; using Microsoft.AspNetCore.Rewrite.Internal.PatternSegments;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
{ {
/// <summary> /// <summary>
/// mod_rewrite lookups for specific string constants. /// mod_rewrite lookups for specific string constants.

View File

@ -5,7 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Rewrite.Internal.PatternSegments; using Microsoft.AspNetCore.Rewrite.Internal.PatternSegments;
namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
{ {
/// <summary> /// <summary>
/// Parses the TestString segment of the mod_rewrite condition. /// Parses the TestString segment of the mod_rewrite condition.

View File

@ -5,7 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace Microsoft.AspNetCore.Rewrite.Internal.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite
{ {
/// <summary> /// <summary>
/// Tokenizes a mod_rewrite rule, delimited by spaces. /// Tokenizes a mod_rewrite rule, delimited by spaces.

View File

@ -3,7 +3,7 @@
using System; using System;
namespace Microsoft.AspNetCore.Rewrite.Internal.CodeRules namespace Microsoft.AspNetCore.Rewrite.Internal
{ {
public class DelegateRule : Rule public class DelegateRule : Rule
{ {

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
{ {
public enum ActionType public enum ActionType
{ {

View File

@ -5,16 +5,16 @@ using System.Collections.Generic;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Rewrite.Logging; using Microsoft.AspNetCore.Rewrite.Logging;
namespace Microsoft.AspNetCore.Rewrite.Internal namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
{ {
public class UrlRewriteRule : Rule public class IISUrlRewriteRule : Rule
{ {
public string Name { get; } public string Name { get; }
public UrlMatch InitialMatch { get; } public UrlMatch InitialMatch { get; }
public IList<Condition> Conditions { get; } public IList<Condition> Conditions { get; }
public UrlAction Action { get; } public UrlAction Action { get; }
public UrlRewriteRule(string name, public IISUrlRewriteRule(string name,
UrlMatch initialMatch, UrlMatch initialMatch,
IList<Condition> conditions, IList<Condition> conditions,
UrlAction action) UrlAction action)

View File

@ -5,7 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Rewrite.Internal.PatternSegments; using Microsoft.AspNetCore.Rewrite.Internal.PatternSegments;
namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
{ {
public class InputParser public class InputParser
{ {

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
{ {
public enum LogicalGrouping public enum LogicalGrouping
{ {

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
{ {
public enum MatchType public enum MatchType
{ {

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
{ {
public enum PatternSyntax public enum PatternSyntax
{ {

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
{ {
public enum RedirectType public enum RedirectType
{ {

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
{ {
public static class RewriteTags public static class RewriteTags
{ {

View File

@ -5,7 +5,7 @@ using System;
using Microsoft.AspNetCore.Rewrite.Internal.PatternSegments; using Microsoft.AspNetCore.Rewrite.Internal.PatternSegments;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
{ {
public static class ServerVariables public static class ServerVariables
{ {

View File

@ -8,20 +8,20 @@ using System.Linq;
using System.Xml; using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
{ {
public class UrlRewriteFileParser public class UrlRewriteFileParser
{ {
private readonly InputParser _inputParser = new InputParser(); private readonly InputParser _inputParser = new InputParser();
public IList<UrlRewriteRule> Parse(TextReader reader) public IList<IISUrlRewriteRule> Parse(TextReader reader)
{ {
var xmlDoc = XDocument.Load(reader, LoadOptions.SetLineInfo); var xmlDoc = XDocument.Load(reader, LoadOptions.SetLineInfo);
var xmlRoot = xmlDoc.Descendants(RewriteTags.Rewrite).FirstOrDefault(); var xmlRoot = xmlDoc.Descendants(RewriteTags.Rewrite).FirstOrDefault();
if (xmlRoot != null) if (xmlRoot != null)
{ {
var result = new List<UrlRewriteRule>(); var result = new List<IISUrlRewriteRule>();
// TODO Global rules are currently not treated differently than normal rules, fix. // TODO Global rules are currently not treated differently than normal rules, fix.
// See: https://github.com/aspnet/BasicMiddleware/issues/59 // See: https://github.com/aspnet/BasicMiddleware/issues/59
ParseRules(xmlRoot.Descendants(RewriteTags.GlobalRules).FirstOrDefault(), result); ParseRules(xmlRoot.Descendants(RewriteTags.GlobalRules).FirstOrDefault(), result);
@ -31,7 +31,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite
return null; return null;
} }
private void ParseRules(XElement rules, IList<UrlRewriteRule> result) private void ParseRules(XElement rules, IList<IISUrlRewriteRule> result)
{ {
if (rules == null) if (rules == null)
{ {
@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite
{ {
var builder = new UrlRewriteRuleBuilder(); var builder = new UrlRewriteRuleBuilder();
ParseRuleAttributes(rule, builder); ParseRuleAttributes(rule, builder);
if (builder.Enabled) if (builder.Enabled)
{ {
result.Add(builder.Build()); result.Add(builder.Build());
@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite
LogicalGrouping grouping; LogicalGrouping grouping;
if (!Enum.TryParse(conditions.Attribute(RewriteTags.MatchType)?.Value, out grouping)) if (!Enum.TryParse(conditions.Attribute(RewriteTags.MatchType)?.Value, out grouping))
{ {
grouping = LogicalGrouping.MatchAll; grouping = LogicalGrouping.MatchAll;
} }
bool trackingAllCaptures; bool trackingAllCaptures;

View File

@ -5,11 +5,10 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Rewrite.Internal.ModRewrite;
using Microsoft.AspNetCore.Rewrite.Internal.UrlActions; using Microsoft.AspNetCore.Rewrite.Internal.UrlActions;
using Microsoft.AspNetCore.Rewrite.Internal.UrlMatches; using Microsoft.AspNetCore.Rewrite.Internal.UrlMatches;
namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite namespace Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite
{ {
public class UrlRewriteRuleBuilder public class UrlRewriteRuleBuilder
{ {
@ -23,14 +22,14 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite
private UrlAction _action; private UrlAction _action;
private bool _matchAny; private bool _matchAny;
public UrlRewriteRule Build() public IISUrlRewriteRule Build()
{ {
if (_initialMatch == null || _action == null) if (_initialMatch == null || _action == null)
{ {
throw new InvalidOperationException("Cannot create UrlRewriteRule without action and match"); throw new InvalidOperationException("Cannot create UrlRewriteRule without action and match");
} }
return new UrlRewriteRule(Name, _initialMatch, _conditions, _action); return new IISUrlRewriteRule(Name, _initialMatch, _conditions, _action);
} }
public void AddUrlAction( public void AddUrlAction(
@ -107,11 +106,11 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite
} }
var regex = new Regex( var regex = new Regex(
pattern, pattern,
ignoreCase ? RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.IgnoreCase : ignoreCase ? RegexOptions.CultureInvariant | RegexOptions.Compiled | RegexOptions.IgnoreCase :
RegexOptions.CultureInvariant | RegexOptions.Compiled, RegexOptions.CultureInvariant | RegexOptions.Compiled,
RegexTimeout); RegexTimeout);
_conditions.Add(new Condition { Input = input, Match = new RegexMatch(regex, negate), OrNext = _matchAny }); _conditions.Add(new Condition { Input = input, Match = new RegexMatch(regex, negate), OrNext = _matchAny });
break; break;
} }

View File

@ -6,7 +6,7 @@ using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNetCore.Rewrite.Internal.CodeRules namespace Microsoft.AspNetCore.Rewrite.Internal
{ {
public class RedirectRule : Rule public class RedirectRule : Rule
{ {
@ -71,7 +71,7 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.CodeRules
var query = context.HttpContext.Request.QueryString.Add( var query = context.HttpContext.Request.QueryString.Add(
QueryString.FromUriComponent( QueryString.FromUriComponent(
newPath.Substring(split))); newPath.Substring(split)));
// not using the HttpContext.Response.redirect here because status codes may be 301, 302, 307, 308 // not using the HttpContext.Response.redirect here because status codes may be 301, 302, 307, 308
response.Headers[HeaderNames.Location] = pathBase + newPath.Substring(0, split) + query; response.Headers[HeaderNames.Location] = pathBase + newPath.Substring(0, split) + query;
} }
else else

View File

@ -4,7 +4,7 @@
using System.Text; using System.Text;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Rewrite.Internal.CodeRules namespace Microsoft.AspNetCore.Rewrite.Internal
{ {
public class RedirectToHttpsRule : Rule public class RedirectToHttpsRule : Rule
{ {

View File

@ -6,7 +6,7 @@ using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Http.Extensions;
namespace Microsoft.AspNetCore.Rewrite.Internal.CodeRules namespace Microsoft.AspNetCore.Rewrite.Internal
{ {
public class RewriteRule : Rule public class RewriteRule : Rule
{ {

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Rewrite.Internal.UrlActions namespace Microsoft.AspNetCore.Rewrite.Internal.UrlActions
{ {

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Rewrite.Internal.UrlActions namespace Microsoft.AspNetCore.Rewrite.Internal.UrlActions
{ {

View File

@ -2,9 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Rewrite.Internal.PatternSegments;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNetCore.Rewrite.Internal.UrlActions namespace Microsoft.AspNetCore.Rewrite.Internal.UrlActions

View File

@ -33,14 +33,14 @@ namespace Microsoft.AspNetCore.Rewrite.Internal.UrlActions
public RewriteAction( public RewriteAction(
RuleTermination result, RuleTermination result,
Pattern pattern, Pattern pattern,
bool queryStringAppend): bool queryStringAppend) :
this (result, this(result,
pattern, pattern,
queryStringAppend, queryStringAppend,
queryStringDelete: false, queryStringDelete: false,
escapeBackReferences: false) escapeBackReferences: false)
{ {
} }
public override void ApplyAction(RewriteContext context, MatchResults ruleMatch, MatchResults condMatch) public override void ApplyAction(RewriteContext context, MatchResults ruleMatch, MatchResults condMatch)

View File

@ -32,9 +32,9 @@ namespace Microsoft.AspNetCore.Rewrite
/// <param name="loggerFactory">The Logger Factory.</param> /// <param name="loggerFactory">The Logger Factory.</param>
/// <param name="options">The middleware options, containing the rules to apply.</param> /// <param name="options">The middleware options, containing the rules to apply.</param>
public RewriteMiddleware( public RewriteMiddleware(
RequestDelegate next, RequestDelegate next,
IHostingEnvironment hostingEnvironment, IHostingEnvironment hostingEnvironment,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
RewriteOptions options) RewriteOptions options)
{ {
if (next == null) if (next == null)
@ -64,7 +64,9 @@ namespace Microsoft.AspNetCore.Rewrite
{ {
throw new ArgumentNullException(nameof(context)); throw new ArgumentNullException(nameof(context));
} }
var rewriteContext = new RewriteContext {
var rewriteContext = new RewriteContext
{
HttpContext = context, HttpContext = context,
StaticFileProvider = _fileProvider, StaticFileProvider = _fileProvider,
Logger = _logger, Logger = _logger,

View File

@ -3,13 +3,11 @@
using System; using System;
using Microsoft.AspNetCore.Rewrite.Internal; using Microsoft.AspNetCore.Rewrite.Internal;
using Microsoft.AspNetCore.Rewrite.Internal.CodeRules;
using Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite;
namespace Microsoft.AspNetCore.Rewrite namespace Microsoft.AspNetCore.Rewrite
{ {
/// <summary> /// <summary>
/// The builder to a list of rules for <see cref="RewriteOptions"/> and <see cref="RewriteMiddleware"/> /// The builder to a list of rules for <see cref="RewriteOptions"/> and <see cref="RewriteMiddleware"/>
/// </summary> /// </summary>
public static class RewriteOptionsExtensions public static class RewriteOptionsExtensions
{ {
@ -90,7 +88,7 @@ namespace Microsoft.AspNetCore.Rewrite
} }
/// <summary> /// <summary>
/// Redirect a request to https if the incoming request is http, with returning a 301 /// Redirect a request to https if the incoming request is http, with returning a 301
/// status code for permanently redirected. /// status code for permanently redirected.
/// </summary> /// </summary>
/// <param name="options"></param> /// <param name="options"></param>

View File

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.AspNetCore.Rewrite.Internal.ModRewrite; using Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Rewrite.Tests.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Tests.ModRewrite

View File

@ -4,7 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNetCore.Rewrite.Internal.ModRewrite; using Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Rewrite.Tests.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Tests.ModRewrite

View File

@ -3,7 +3,7 @@
using System; using System;
using System.IO; using System.IO;
using Microsoft.AspNetCore.Rewrite.Internal.ModRewrite; using Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Rewrite.Tests.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Tests.ModRewrite

View File

@ -3,7 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Rewrite.Internal.ModRewrite; using Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Rewrite.Tests.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Tests.ModRewrite

View File

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.AspNetCore.Rewrite.Internal.ModRewrite; using Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Rewrite.Tests.ModRewrite namespace Microsoft.AspNetCore.Rewrite.Tests.ModRewrite

View File

@ -4,7 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Rewrite.Internal; using Microsoft.AspNetCore.Rewrite.Internal;
using Microsoft.AspNetCore.Rewrite.Internal.ModRewrite; using Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite;
using Microsoft.AspNetCore.Rewrite.Internal.PatternSegments; using Microsoft.AspNetCore.Rewrite.Internal.PatternSegments;
using Xunit; using Xunit;

View File

@ -5,10 +5,10 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Rewrite.Internal; using Microsoft.AspNetCore.Rewrite.Internal;
using Microsoft.AspNetCore.Rewrite.Internal.ModRewrite; using Microsoft.AspNetCore.Rewrite.Internal.ApacheModRewrite;
using Microsoft.AspNetCore.Rewrite.Internal.UrlActions; using Microsoft.AspNetCore.Rewrite.Internal.UrlActions;
using Microsoft.AspNetCore.Rewrite.Internal.UrlMatches; using Microsoft.AspNetCore.Rewrite.Internal.UrlMatches;
using Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite; using Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Rewrite.Tests.UrlRewrite namespace Microsoft.AspNetCore.Rewrite.Tests.UrlRewrite
@ -28,7 +28,7 @@ namespace Microsoft.AspNetCore.Rewrite.Tests.UrlRewrite
</rules> </rules>
</rewrite>"; </rewrite>";
var expected = new List<UrlRewriteRule>(); var expected = new List<IISUrlRewriteRule>();
expected.Add(CreateTestRule(new List<Condition>(), expected.Add(CreateTestRule(new List<Condition>(),
url: "^article/([0-9]+)/([_0-9a-z-]+)", url: "^article/([0-9]+)/([_0-9a-z-]+)",
name: "Rewrite to article.aspx", name: "Rewrite to article.aspx",
@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.Rewrite.Tests.UrlRewrite
Match = new RegexMatch(new Regex("^OFF$"), false) Match = new RegexMatch(new Regex("^OFF$"), false)
}); });
var expected = new List<UrlRewriteRule>(); var expected = new List<IISUrlRewriteRule>();
expected.Add(CreateTestRule(condList, expected.Add(CreateTestRule(condList,
url: "^article/([0-9]+)/([_0-9a-z-]+)", url: "^article/([0-9]+)/([_0-9a-z-]+)",
name: "Rewrite to article.aspx", name: "Rewrite to article.aspx",
@ -109,7 +109,7 @@ namespace Microsoft.AspNetCore.Rewrite.Tests.UrlRewrite
Match = new RegexMatch(new Regex("^OFF$"), false) Match = new RegexMatch(new Regex("^OFF$"), false)
}); });
var expected = new List<UrlRewriteRule>(); var expected = new List<IISUrlRewriteRule>();
expected.Add(CreateTestRule(condList, expected.Add(CreateTestRule(condList,
url: "^article/([0-9]+)/([_0-9a-z-]+)", url: "^article/([0-9]+)/([_0-9a-z-]+)",
name: "Rewrite to article.aspx", name: "Rewrite to article.aspx",
@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.Rewrite.Tests.UrlRewrite
} }
// Creates a rule with appropriate default values of the url rewrite rule. // Creates a rule with appropriate default values of the url rewrite rule.
private UrlRewriteRule CreateTestRule(List<Condition> conditions, private IISUrlRewriteRule CreateTestRule(List<Condition> conditions,
LogicalGrouping condGrouping = LogicalGrouping.MatchAll, LogicalGrouping condGrouping = LogicalGrouping.MatchAll,
bool condTracking = false, bool condTracking = false,
string name = "", string name = "",
@ -146,12 +146,12 @@ namespace Microsoft.AspNetCore.Rewrite.Tests.UrlRewrite
RedirectType redirectType = RedirectType.Permanent RedirectType redirectType = RedirectType.Permanent
) )
{ {
return new UrlRewriteRule(name, new RegexMatch(new Regex("^OFF$"), false), conditions, return new IISUrlRewriteRule(name, new RegexMatch(new Regex("^OFF$"), false), conditions,
new RewriteAction(RuleTermination.Continue, new InputParser().ParseInputString(url), queryStringAppend: false)); new RewriteAction(RuleTermination.Continue, new InputParser().ParseInputString(url), queryStringAppend: false));
} }
// TODO make rules comparable? // TODO make rules comparable?
private void AssertUrlRewriteRuleEquality(IList<UrlRewriteRule> actual, IList<UrlRewriteRule> expected) private void AssertUrlRewriteRuleEquality(IList<IISUrlRewriteRule> actual, IList<IISUrlRewriteRule> expected)
{ {
Assert.Equal(actual.Count, expected.Count); Assert.Equal(actual.Count, expected.Count);
for (var i = 0; i < actual.Count; i++) for (var i = 0; i < actual.Count; i++)

View File

@ -3,7 +3,7 @@
using System; using System;
using System.IO; using System.IO;
using Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite; using Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Rewrite.Tests.UrlRewrite namespace Microsoft.AspNetCore.Rewrite.Tests.UrlRewrite

View File

@ -5,7 +5,7 @@ using System;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Rewrite.Internal; using Microsoft.AspNetCore.Rewrite.Internal;
using Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite; using Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Rewrite.Tests.UrlRewrite namespace Microsoft.AspNetCore.Rewrite.Tests.UrlRewrite

View File

@ -4,7 +4,7 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Rewrite.Internal; using Microsoft.AspNetCore.Rewrite.Internal;
using Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite; using Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
using Xunit; using Xunit;

View File

@ -4,7 +4,7 @@
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Rewrite.Internal.UrlRewrite; using Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite;
using Xunit; using Xunit;
namespace Microsoft.AspNetCore.Rewrite.Tests.UrlRewrite namespace Microsoft.AspNetCore.Rewrite.Tests.UrlRewrite