Skip to content

Commit

Permalink
added support for - (dash) substition or more percisely none
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Berardi committed Jul 8, 2011
1 parent c5123fe commit 3397969
Show file tree
Hide file tree
Showing 26 changed files with 56 additions and 26 deletions.
6 changes: 6 additions & 0 deletions src/Engines/ApacheRuleSet.cs
Expand Up @@ -427,7 +427,13 @@ public void RefreshRules(TextReader reader)
{
switch (parts[0])
{
case "inherit":
break;

// obsolete in 2.1 mod_rewrite
case "MaxRedirects":
Manager.LogIf(tempLogLevel >= 1, "MaxRedirects is obsolete", "Obsolete");

int maxInternalTransfers;
if (Int32.TryParse(parts[1], out maxInternalTransfers))
{
Expand Down
6 changes: 6 additions & 0 deletions src/Rules/DefaultRuleAction.cs
Expand Up @@ -117,6 +117,12 @@ public virtual bool IsMatch(RuleContext context)
/// <returns></returns>
public virtual void Execute(RuleContext context)
{
if (_substitution == "-")
{
Manager.LogIf(context.LogLevel >= 2, "Output: " + context.CurrentUrl, context.LogCategory);
return;
}

string inputUrl = context.CurrentUrl.AbsolutePath;
string substituedUrl = Pattern.Replace(inputUrl, _substitution, context);

Expand Down
20 changes: 19 additions & 1 deletion test/ManagedFusion.Rewriter.Tests/ApacheStyleTest.cs
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using NUnit.Framework;

namespace ManagedFusion.Rewriter.Test
namespace ManagedFusion.Rewriter.Tests
{
[TestFixture]
public class ApacheStyleTest : BaseTest
Expand Down Expand Up @@ -89,6 +89,24 @@ public void RewriteCondWithHttpHeader()
Assert.AreEqual(expected, result);
}

[Test]
public void SimpleRule_WithNoSubstituion()
{
var target = CreateRuleSet(@"
RewriteRule ^.* - [F,L]");

var url = new Uri("http://www.somesite.com/test.aspx");
var context = HttpHelpers.MockHttpContext(url);
context.Request.SetServerVariables(new Dictionary<string, string> {
{ "REQUEST_URI", url.GetComponents(UriComponents.PathAndQuery, UriFormat.SafeUnescaped) }
});

Uri expected = null; // no change
Uri result = target.RunRules(context, url);

Assert.AreEqual(expected, result);
}

[Test]
public void SimpleRule_WithComplexCondition()
{
Expand Down
2 changes: 1 addition & 1 deletion test/ManagedFusion.Rewriter.Tests/BaseTest.cs
Expand Up @@ -7,7 +7,7 @@
using ManagedFusion.Rewriter.Engines;
using System.Text.RegularExpressions;

namespace ManagedFusion.Rewriter.Test
namespace ManagedFusion.Rewriter.Tests
{
public class BaseTest
{
Expand Down
2 changes: 1 addition & 1 deletion test/ManagedFusion.Rewriter.Tests/CommonProblemTest.cs
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using NUnit.Framework;

namespace ManagedFusion.Rewriter.Test
namespace ManagedFusion.Rewriter.Tests
{
[TestFixture]
public class CommonProblemTest : BaseTest
Expand Down
2 changes: 1 addition & 1 deletion test/ManagedFusion.Rewriter.Tests/CommonUseTest.cs
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using NUnit.Framework;

namespace ManagedFusion.Rewriter.Test
namespace ManagedFusion.Rewriter.Tests
{
[TestFixture]
public class CommonUseTest : BaseTest
Expand Down
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using NUnit.Framework;

namespace ManagedFusion.Rewriter.Test.Conditions.Flags
namespace ManagedFusion.Rewriter.Tests.Conditions.Flags
{
/// <summary>
/// Summary description for NoCaseTest
Expand Down
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using NUnit.Framework;

namespace ManagedFusion.Rewriter.Test.Conditions.Flags
namespace ManagedFusion.Rewriter.Tests.Conditions.Flags
{
/// <summary>
/// Summary description for OrNextTest
Expand Down
2 changes: 1 addition & 1 deletion test/ManagedFusion.Rewriter.Tests/HttpHelpers.cs
Expand Up @@ -6,7 +6,7 @@
using System.Collections;
using System.IO;

namespace ManagedFusion.Rewriter.Test
namespace ManagedFusion.Rewriter.Tests
{
public static class HttpHelpers
{
Expand Down
2 changes: 1 addition & 1 deletion test/ManagedFusion.Rewriter.Tests/KnownHttpVerbTest.cs
Expand Up @@ -4,7 +4,7 @@
using System.Linq;
using NUnit.Framework;

namespace ManagedFusion.Rewriter.Test
namespace ManagedFusion.Rewriter.Tests
{
/// <summary>
/// Summary description for KnownHttpVerbTest
Expand Down
2 changes: 1 addition & 1 deletion test/ManagedFusion.Rewriter.Tests/PatternTest.cs
Expand Up @@ -3,7 +3,7 @@
using NUnit.Framework;
using System.Text.RegularExpressions;

namespace ManagedFusion.Rewriter.Test
namespace ManagedFusion.Rewriter.Tests
{
[TestFixture]
public class PatternTest : BaseTest
Expand Down
2 changes: 1 addition & 1 deletion test/ManagedFusion.Rewriter.Tests/ProxyTest.cs
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using NUnit.Framework;

namespace ManagedFusion.Rewriter.Test
namespace ManagedFusion.Rewriter.Tests
{
[TestFixture]
public class ProxyTest : BaseTest
Expand Down
Expand Up @@ -2,10 +2,10 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
using NUnit.Framework;
using ManagedFusion.Rewriter.Test;
using ManagedFusion.Rewriter.Conditions;
using ManagedFusion.Rewriter.Rules;

namespace ManagedFusion.Rewriter.Rules.Test
namespace ManagedFusion.Rewriter.Tests.Rules
{
[TestFixture]
public class DefaultOutputRuleActionTest : BaseTest
Expand Down
@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using ManagedFusion.Rewriter.Test;
using ManagedFusion.Rewriter.Conditions;
using NUnit.Framework;
using ManagedFusion.Rewriter.Rules;

namespace ManagedFusion.Rewriter.Rules.Test
namespace ManagedFusion.Rewriter.Tests.Rules
{
[TestFixture]
public class DefaultRuleActionTest : BaseTest
Expand Down
@@ -1,7 +1,7 @@
using System;
using NUnit.Framework;

namespace ManagedFusion.Rewriter.Test.Rules.Flags
namespace ManagedFusion.Rewriter.Tests.Rules.Flags
{
/// <summary>
/// Summary description for ChainFlagTest
Expand Down
@@ -1,7 +1,7 @@
using System;
using NUnit.Framework;

namespace ManagedFusion.Rewriter.Test.Rules.Flags
namespace ManagedFusion.Rewriter.Tests.Rules.Flags
{
/// <summary>
/// Summary description for LastFlagTest
Expand Down
@@ -1,7 +1,7 @@
using System;
using NUnit.Framework;

namespace ManagedFusion.Rewriter.Test.Rules.Flags
namespace ManagedFusion.Rewriter.Tests.Rules.Flags
{
/// <summary>
/// Summary description for NextRuleFlagTest
Expand Down
Expand Up @@ -4,7 +4,7 @@
using System.Linq;
using NUnit.Framework;

namespace ManagedFusion.Rewriter.Test.Rules.Flags
namespace ManagedFusion.Rewriter.Tests.Rules.Flags
{
/// <summary>
/// Summary description for NoCaseTest
Expand Down
@@ -1,7 +1,7 @@
using System;
using NUnit.Framework;

namespace ManagedFusion.Rewriter.Test.Rules.Flags
namespace ManagedFusion.Rewriter.Tests.Rules.Flags
{
[TestFixture]
public class QueryStringAppendFlagTest : BaseTest
Expand Down
@@ -1,7 +1,7 @@
using System;
using NUnit.Framework;

namespace ManagedFusion.Rewriter.Test.Rules.Flags
namespace ManagedFusion.Rewriter.Tests.Rules.Flags
{
/// <summary>
/// Summary description for ChainFlagTest
Expand Down
@@ -1,7 +1,7 @@
using System;
using NUnit.Framework;

namespace ManagedFusion.Rewriter.Test.Rules.Flags
namespace ManagedFusion.Rewriter.Tests.Rules.Flags
{
[TestFixture]
public class SkipRuleFlagTest : BaseTest
Expand Down
2 changes: 1 addition & 1 deletion test/ManagedFusion.Rewriter.Tests/RulesHelper.cs
@@ -1,7 +1,7 @@
using System;
using Moq;

namespace ManagedFusion.Rewriter.Test
namespace ManagedFusion.Rewriter.Tests
{
public static class RulesHelper
{
Expand Down
2 changes: 1 addition & 1 deletion test/ManagedFusion.Rewriter.Tests/StringExtensions.cs
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using System.Text;

namespace ManagedFusion.Rewriter.Test
namespace ManagedFusion.Rewriter.Tests
{
public static class StringExtensions
{
Expand Down
2 changes: 1 addition & 1 deletion test/ManagedFusion.Rewriter.Tests/TestProxyAsyncHandler.cs
Expand Up @@ -5,7 +5,7 @@
using System.Web;
using System.Net;

namespace ManagedFusion.Rewriter.Test
namespace ManagedFusion.Rewriter.Tests
{
public class TestProxyAsyncHandler : ProxyAsyncHandler
{
Expand Down
2 changes: 1 addition & 1 deletion test/ManagedFusion.Rewriter.Tests/TestProxyHandler.cs
Expand Up @@ -5,7 +5,7 @@
using System.Web;
using System.Net;

namespace ManagedFusion.Rewriter.Test
namespace ManagedFusion.Rewriter.Tests
{
public class TestProxyHandler : ProxyHandler
{
Expand Down
2 changes: 1 addition & 1 deletion test/ManagedFusion.Rewriter.Tests/TestRuleAction.cs
@@ -1,6 +1,6 @@
using System;

namespace ManagedFusion.Rewriter.Test
namespace ManagedFusion.Rewriter.Tests
{
public class TestRuleAction : IRuleAction
{
Expand Down

0 comments on commit 3397969

Please sign in to comment.