summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework/RewriteSubdomainRule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI.Web/Framework/RewriteSubdomainRule.cs')
-rw-r--r--src/SMAPI.Web/Framework/RewriteSubdomainRule.cs30
1 files changed, 0 insertions, 30 deletions
diff --git a/src/SMAPI.Web/Framework/RewriteSubdomainRule.cs b/src/SMAPI.Web/Framework/RewriteSubdomainRule.cs
deleted file mode 100644
index 5a56844f..00000000
--- a/src/SMAPI.Web/Framework/RewriteSubdomainRule.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using System;
-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
- {
- /// <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;
-
- // get host parts
- string host = context.HttpContext.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
- context.HttpContext.Request.Path = $"/{parts[0]}{context.HttpContext.Request.Path}";
- }
- }
-}