#17906: Fixing shell resolution when no header is sent

Work Item:17906

--HG--
branch : 1.x
This commit is contained in:
sberry3057
2012-02-17 10:10:00 -08:00
parent 4a59815326
commit 062f214cbb
+8 -8
View File
@@ -51,14 +51,15 @@ namespace Orchard.Environment {
var qualified = var qualified =
_shells.Where(x => !string.IsNullOrEmpty(x.RequestUrlHost) || !string.IsNullOrEmpty(x.RequestUrlPrefix)); _shells.Where(x => !string.IsNullOrEmpty(x.RequestUrlHost) || !string.IsNullOrEmpty(x.RequestUrlPrefix));
var unqualified = var unqualified = _shells
_shells.Where(x => string.IsNullOrEmpty(x.RequestUrlHost) && string.IsNullOrEmpty(x.RequestUrlPrefix)); .Where(x => string.IsNullOrEmpty(x.RequestUrlHost) && string.IsNullOrEmpty(x.RequestUrlPrefix))
.ToList();
_shellsByHost = qualified _shellsByHost = qualified
.SelectMany(s => s.RequestUrlHost == null || s.RequestUrlHost.IndexOf(',') == -1 ? new[] {s} : .SelectMany(s => s.RequestUrlHost == null || s.RequestUrlHost.IndexOf(',') == -1 ? new[] {s} :
s.RequestUrlHost.Split(new [] {','}, StringSplitOptions.RemoveEmptyEntries) s.RequestUrlHost.Split(new [] {','}, StringSplitOptions.RemoveEmptyEntries)
.Select(h => new ShellSettings(s) {RequestUrlHost = h})) .Select(h => new ShellSettings(s) {RequestUrlHost = h}))
.GroupBy(s => s.RequestUrlHost ?? "") .GroupBy(s => s.RequestUrlHost ?? string.Empty)
.OrderByDescending(g => g.Key.Length); .OrderByDescending(g => g.Key.Length);
if (unqualified.Count() == 1) { if (unqualified.Count() == 1) {
@@ -79,11 +80,11 @@ namespace Orchard.Environment {
} }
public ShellSettings Match(HttpContextBase httpContext) { public ShellSettings Match(HttpContextBase httpContext) {
return Match(httpContext.Request.Headers["Host"], httpContext.Request.AppRelativeCurrentExecutionFilePath); // use Host header to prevent proxy alteration of the orignal request
return Match(httpContext.Request.Headers["Host"] ?? string.Empty, httpContext.Request.AppRelativeCurrentExecutionFilePath);
} }
public ShellSettings Match(string host, string appRelativePath) { public ShellSettings Match(string host, string appRelativePath) {
// use Host header to prevent proxy alteration of the orignal request
var hostLength = host.IndexOf(':'); var hostLength = host.IndexOf(':');
if (hostLength != -1) if (hostLength != -1)
host = host.Substring(0, hostLength); host = host.Substring(0, hostLength);
@@ -91,9 +92,8 @@ namespace Orchard.Environment {
var mostQualifiedMatch = _shellsByHost var mostQualifiedMatch = _shellsByHost
.Where(group => host.EndsWith(group.Key, StringComparison.OrdinalIgnoreCase)) .Where(group => host.EndsWith(group.Key, StringComparison.OrdinalIgnoreCase))
.SelectMany(group => group .SelectMany(group => group
.OrderByDescending(settings => (settings.RequestUrlPrefix ?? "").Length)) .OrderByDescending(settings => (settings.RequestUrlPrefix ?? string.Empty).Length))
.Where(settings => settings.State.CurrentState != TenantState.State.Disabled && appRelativePath.StartsWith(settings.RequestUrlPrefix ?? "", StringComparison.OrdinalIgnoreCase)) .FirstOrDefault(settings => settings.State.CurrentState != TenantState.State.Disabled && appRelativePath.StartsWith(settings.RequestUrlPrefix ?? string.Empty, StringComparison.OrdinalIgnoreCase));
.FirstOrDefault();
return mostQualifiedMatch ?? _fallback; return mostQualifiedMatch ?? _fallback;
} }