diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-10-28 11:53:54 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-10-28 11:53:54 -0400 |
commit | c6d8333c7a28b752397e171540306ceccf74ca12 (patch) | |
tree | 335dfe7fe46db592490c81e4850b8ad6adcb232a /src/SMAPI.Web/Framework/RewriteSubdomainRule.cs | |
parent | ed03048828d83afa555c97f0ccfbeaa6e84ead6a (diff) | |
download | SMAPI-c6d8333c7a28b752397e171540306ceccf74ca12.tar.gz SMAPI-c6d8333c7a28b752397e171540306ceccf74ca12.tar.bz2 SMAPI-c6d8333c7a28b752397e171540306ceccf74ca12.zip |
improve criteria for subdomain rewriting (#358)
Diffstat (limited to 'src/SMAPI.Web/Framework/RewriteSubdomainRule.cs')
-rw-r--r-- | src/SMAPI.Web/Framework/RewriteSubdomainRule.cs | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/src/SMAPI.Web/Framework/RewriteSubdomainRule.cs b/src/SMAPI.Web/Framework/RewriteSubdomainRule.cs deleted file mode 100644 index cc183fe3..00000000 --- a/src/SMAPI.Web/Framework/RewriteSubdomainRule.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Linq; -using System.Text.RegularExpressions; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Rewrite; - -namespace StardewModdingAPI.Web.Framework -{ - /// <summary>Rewrite requests to prepend the subdomain portion (if any) to the path.</summary> - /// <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 = request.Host.Host; - string[] parts = host.Split('.'); - - // validate - if (parts.Length < 2) - return; - if (parts.Length < 3 && !"localhost".Equals(parts[1], StringComparison.InvariantCultureIgnoreCase)) - return; - - // prepend to path - request.Path = $"/{parts[0]}{request.Path}"; - } - } -} |