summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework/RewriteSubdomainRule.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-10-27 21:10:36 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-10-27 21:10:36 -0400
commit3f43ebcc0e31db523fa82a163374cebf2f577cde (patch)
tree8b41f6cdd9f2894638e7be94e7268220184a9c76 /src/SMAPI.Web/Framework/RewriteSubdomainRule.cs
parentad5bb5b49af49c4668fd30fb2a0e606dcefe4ec0 (diff)
downloadSMAPI-3f43ebcc0e31db523fa82a163374cebf2f577cde.tar.gz
SMAPI-3f43ebcc0e31db523fa82a163374cebf2f577cde.tar.bz2
SMAPI-3f43ebcc0e31db523fa82a163374cebf2f577cde.zip
fix issues with subdomain routing in log UI (#358)
Diffstat (limited to 'src/SMAPI.Web/Framework/RewriteSubdomainRule.cs')
-rw-r--r--src/SMAPI.Web/Framework/RewriteSubdomainRule.cs22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/SMAPI.Web/Framework/RewriteSubdomainRule.cs b/src/SMAPI.Web/Framework/RewriteSubdomainRule.cs
index 5a56844f..cc183fe3 100644
--- a/src/SMAPI.Web/Framework/RewriteSubdomainRule.cs
+++ b/src/SMAPI.Web/Framework/RewriteSubdomainRule.cs
@@ -1,4 +1,7 @@
using System;
+using System.Linq;
+using System.Text.RegularExpressions;
+using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Rewrite;
namespace StardewModdingAPI.Web.Framework
@@ -7,14 +10,29 @@ namespace StardewModdingAPI.Web.Framework
/// <remarks>Derived from <a href="https://stackoverflow.com/a/44526747/262123" />.</remarks>
internal class RewriteSubdomainRule : IRule
{
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The paths (excluding the hostname portion) to not rewrite.</summary>
+ public Regex[] ExceptPaths { get; set; }
+
+
+ /*********
+ ** Public methods
+ *********/
/// <summary>Applies the rule. Implementations of ApplyRule should set the value for <see cref="RewriteContext.Result" /> (defaults to RuleResult.ContinueRules).</summary>
/// <param name="context">The rewrite context.</param>
public void ApplyRule(RewriteContext context)
{
context.Result = RuleResult.ContinueRules;
+ HttpRequest request = context.HttpContext.Request;
+
+ // check ignores
+ if (this.ExceptPaths?.Any(pattern => pattern.IsMatch(request.Path)) == true)
+ return;
// get host parts
- string host = context.HttpContext.Request.Host.Host;
+ string host = request.Host.Host;
string[] parts = host.Split('.');
// validate
@@ -24,7 +42,7 @@ namespace StardewModdingAPI.Web.Framework
return;
// prepend to path
- context.HttpContext.Request.Path = $"/{parts[0]}{context.HttpContext.Request.Path}";
+ request.Path = $"/{parts[0]}{request.Path}";
}
}
}