Added rewrite property to outbound rules. Added capability to clear the action url of an inbound/global rule.
This commit is contained in:
Родитель
5557135918
Коммит
4164b66874
|
@ -74,7 +74,12 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
return ((string)(base["url"]));
|
||||
}
|
||||
set {
|
||||
base["url"] = value;
|
||||
if (string.IsNullOrEmpty(value)) {
|
||||
base.GetAttribute("url").Delete();
|
||||
}
|
||||
else {
|
||||
base["url"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,15 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
base["replace"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public new OutboundActionType Type {
|
||||
get {
|
||||
return ((OutboundActionType)(base["type"]));
|
||||
}
|
||||
set {
|
||||
base["type"] = ((int)(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
|
||||
namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
||||
{
|
||||
public enum OutboundActionType
|
||||
{
|
||||
None = 0,
|
||||
Rewrite = 1
|
||||
}
|
||||
}
|
|
@ -484,6 +484,12 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
if (rule.Schema.HasAttribute(InboundRule.ResponseCacheDirectiveAttribute)) {
|
||||
DynamicHelper.If((object)model.response_cache_directive, v => rule.ResponseCacheDirective = ResponseCacheDirectiveHelper.FromJsonModel(v));
|
||||
}
|
||||
|
||||
//
|
||||
// Check set to valid state
|
||||
if ((rule.Action.Type == ActionType.Redirect || rule.Action.Type == ActionType.Rewrite) && string.IsNullOrEmpty(rule.Action.Url)) {
|
||||
throw new ApiArgumentException("action.url");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -513,6 +513,12 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
if (rule.Schema.HasAttribute(InboundRule.ResponseCacheDirectiveAttribute)) {
|
||||
DynamicHelper.If((object)model.response_cache_directive, v => rule.ResponseCacheDirective = ResponseCacheDirectiveHelper.FromJsonModel(v));
|
||||
}
|
||||
|
||||
//
|
||||
// Check set to valid state
|
||||
if ((rule.Action.Type == ActionType.Redirect || rule.Action.Type == ActionType.Rewrite) && string.IsNullOrEmpty(rule.Action.Url)) {
|
||||
throw new ApiArgumentException("action.url");
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddAllowedServerVariable(AllowedServerVariablesSection serverVariablesSection, string name)
|
||||
|
|
|
@ -333,6 +333,12 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
obj.stop_processing = rule.StopProcessing;
|
||||
}
|
||||
|
||||
//
|
||||
// rewrite
|
||||
if (fields.Exists("rewrite")) {
|
||||
obj.rewrite = rule.Action.Type == OutboundActionType.Rewrite ? true : false;
|
||||
}
|
||||
|
||||
//
|
||||
// rewrite_value
|
||||
if (fields.Exists("rewrite_value")) {
|
||||
|
@ -432,6 +438,10 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
|
||||
var rule = (OutboundRule)section.Rules.CreateElement();
|
||||
|
||||
//
|
||||
// Default to rewrite rule
|
||||
rule.Action.Type = OutboundActionType.Rewrite;
|
||||
|
||||
SetRule(model, rule, section);
|
||||
|
||||
return rule;
|
||||
|
@ -688,6 +698,7 @@ namespace Microsoft.IIS.Administration.WebServer.UrlRewrite
|
|||
}
|
||||
|
||||
DynamicHelper.If((object)model.pattern, v => rule.Match.Pattern = v);
|
||||
DynamicHelper.If<bool>((object)model.rewrite, v => rule.Action.Type = v ? OutboundActionType.Rewrite : OutboundActionType.None);
|
||||
DynamicHelper.If((object)model.rewrite_value, v => rule.Action.RewriteValue = v);
|
||||
DynamicHelper.If<bool>((object)model.ignore_case, v => rule.Match.IgnoreCase = v);
|
||||
DynamicHelper.If<bool>((object)model.negate, v => rule.Match.Negate = v);
|
||||
|
|
|
@ -549,6 +549,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
ignore_case = false,
|
||||
negate = true,
|
||||
stop_processing = false,
|
||||
rewrite = false,
|
||||
rewrite_value = "test rewrite value",
|
||||
condition_match_constraints = "match_any",
|
||||
track_all_captures = true,
|
||||
|
@ -582,6 +583,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
ignore_case = true,
|
||||
negate = false,
|
||||
stop_processing = true,
|
||||
rewrite = true,
|
||||
rewrite_value = "test rewrite update",
|
||||
condition_match_constraints = "match_all",
|
||||
track_all_captures = false,
|
||||
|
@ -881,6 +883,7 @@ namespace Microsoft.IIS.Administration.Tests
|
|||
Assert.Equal(a.Value<bool>("ignore_case"), b.Value<bool>("ignore_case"));
|
||||
Assert.Equal(a.Value<bool>("negate"), b.Value<bool>("negate"));
|
||||
Assert.Equal(a.Value<bool>("stop_processing"), b.Value<bool>("stop_processing"));
|
||||
Assert.Equal(a.Value<bool>("rewrite"), b.Value<bool>("rewrite"));
|
||||
Assert.Equal(a.Value<string>("rewrite_value"), b.Value<string>("rewrite_value"));
|
||||
Assert.Equal(a.Value<string>("condition_match_constraints"), b.Value<string>("condition_match_constraints"));
|
||||
Assert.Equal(a.Value<bool>("track_all_captures"), b.Value<bool>("track_all_captures"));
|
||||
|
|
Загрузка…
Ссылка в новой задаче