Framework/UI/Resources: Removing ResourceDefinition.CdnSupportsSsl

Discussion: https://github.com/OrchardCMS/Orchard/issues/6941
This commit is contained in:
Lombiq 2019-08-29 23:53:55 +02:00 committed by Benedek Farkas
parent e7bcd916a9
commit ac11024be4
4 changed files with 18 additions and 40 deletions

View File

@ -36,7 +36,8 @@ namespace Orchard.Tests.UI.Resources {
private void VerifyPaths(string resourceType, RequireSettings defaultSettings, string expectedPaths, bool ssl) { private void VerifyPaths(string resourceType, RequireSettings defaultSettings, string expectedPaths, bool ssl) {
defaultSettings = defaultSettings ?? new RequireSettings(); defaultSettings = defaultSettings ?? new RequireSettings();
var requiredResources = _resourceManager.BuildRequiredResources(resourceType); var requiredResources = _resourceManager.BuildRequiredResources(resourceType);
var renderedResources = string.Join(",", requiredResources.Select(context => context.GetResourceUrl(defaultSettings, _appPath, ssl, _resourceFileHashProvider)).ToArray()); var renderedResources = string.Join(",", requiredResources.Select(context => context
.GetResourceUrl(defaultSettings, _appPath, _resourceFileHashProvider)).ToArray());
Assert.That(renderedResources, Is.EqualTo(expectedPaths)); Assert.That(renderedResources, Is.EqualTo(expectedPaths));
} }
@ -111,7 +112,7 @@ namespace Orchard.Tests.UI.Resources {
[Test] [Test]
public void LocalPathIsUsedInCdnModeNotSupportsSsl() { public void LocalPathIsUsedInCdnModeNotSupportsSsl() {
_testManifest.DefineManifest = m => { _testManifest.DefineManifest = m => {
m.DefineResource("script", "Script1").SetUrl("script1.min.js", "script1.js").SetCdn("http://cdn/script1.min.js", "http://cdn/script1.js", false); m.DefineResource("script", "Script1").SetUrl("script1.min.js", "script1.js").SetCdn("http://cdn/script1.min.js", "http://cdn/script1.js");
}; };
_resourceManager.Require("script", "Script1"); _resourceManager.Require("script", "Script1");
VerifyPaths("script", new RequireSettings { CdnMode = true }, "script1.min.js", true); VerifyPaths("script", new RequireSettings { CdnMode = true }, "script1.min.js", true);
@ -120,7 +121,7 @@ namespace Orchard.Tests.UI.Resources {
[Test] [Test]
public void LocalDebugPathIsUsedInCdnModeNotSupportsSslAndDebug() { public void LocalDebugPathIsUsedInCdnModeNotSupportsSslAndDebug() {
_testManifest.DefineManifest = m => { _testManifest.DefineManifest = m => {
m.DefineResource("script", "Script1").SetUrl("script1.min.js", "script1.js").SetCdn("http://cdn/script1.min.js", "http://cdn/script1.js", false); m.DefineResource("script", "Script1").SetUrl("script1.min.js", "script1.js").SetCdn("http://cdn/script1.min.js", "http://cdn/script1.js");
}; };
_resourceManager.Require("script", "Script1"); _resourceManager.Require("script", "Script1");
VerifyPaths("script", new RequireSettings { CdnMode = true, DebugMode = true }, "script1.js", true); VerifyPaths("script", new RequireSettings { CdnMode = true, DebugMode = true }, "script1.js", true);

View File

@ -459,12 +459,11 @@ namespace Orchard.Core.Shapes {
var appPath = httpContext == null || httpContext.Request == null var appPath = httpContext == null || httpContext.Request == null
? null ? null
: httpContext.Request.ApplicationPath; : httpContext.Request.ApplicationPath;
var ssl = httpContext != null && httpContext.Request != null && httpContext.Request.IsSecureConnection;
foreach (var context in requiredResources.Where(r => foreach (var context in requiredResources.Where(r =>
(includeLocation.HasValue ? r.Settings.Location == includeLocation.Value : true) && (includeLocation.HasValue ? r.Settings.Location == includeLocation.Value : true) &&
(excludeLocation.HasValue ? r.Settings.Location != excludeLocation.Value : true))) { (excludeLocation.HasValue ? r.Settings.Location != excludeLocation.Value : true))) {
var url = context.GetResourceUrl(defaultSettings, appPath, ssl, _resourceFileHashProvider); var url = context.GetResourceUrl(defaultSettings, appPath, _resourceFileHashProvider);
var condition = context.Settings.Condition; var condition = context.Settings.Condition;
var attributes = context.Settings.HasAttributes ? context.Settings.Attributes : null; var attributes = context.Settings.HasAttributes ? context.Settings.Attributes : null;
IHtmlString result; IHtmlString result;

View File

@ -120,8 +120,6 @@ namespace Orchard.UI.Resources {
} }
public string[] Cultures { get; private set; } public string[] Cultures { get; private set; }
[Obsolete("This parameter has no effect on the resource URL.")]
public bool CdnSupportsSsl { get; private set; }
public IEnumerable<string> Dependencies { get; private set; } public IEnumerable<string> Dependencies { get; private set; }
public string FilePathAttributeName { get; private set; } public string FilePathAttributeName { get; private set; }
public TagBuilder TagBuilder { get; private set; } public TagBuilder TagBuilder { get; private set; }
@ -167,17 +165,9 @@ namespace Orchard.UI.Resources {
if (!string.IsNullOrWhiteSpace(cdnUrlDebug)) UrlCdnDebug = cdnUrlDebug; if (!string.IsNullOrWhiteSpace(cdnUrlDebug)) UrlCdnDebug = cdnUrlDebug;
else {
CdnSupportsSsl = cdnUrl.StartsWith("https", StringComparison.OrdinalIgnoreCase);
}
return this; return this;
} }
[Obsolete("Use SetCdn without the \"cdnSupportsSsl\" parameter instead as it has no effect.")]
public ResourceDefinition SetCdn(string cdnUrl, string cdnUrlDebug, bool cdnSupportsSsl) {
return SetCdn(cdnUrl, cdnUrlDebug);
}
public ResourceDefinition SetPhysicalPath(string physicalPath) { public ResourceDefinition SetPhysicalPath(string physicalPath) {
return SetPhysicalPath(physicalPath, null); return SetPhysicalPath(physicalPath, null);
} }
@ -213,29 +203,18 @@ namespace Orchard.UI.Resources {
} }
public string ResolveUrl(RequireSettings settings, string applicationPath, IResourceFileHashProvider resourceFileHashProvider) { public string ResolveUrl(RequireSettings settings, string applicationPath, IResourceFileHashProvider resourceFileHashProvider) {
return ResolveUrl(settings, applicationPath, false, resourceFileHashProvider);
}
public string ResolveUrl(RequireSettings settings, string applicationPath, bool ssl, IResourceFileHashProvider resourceFileHashProvider) {
string url; string url;
string physicalPath = null; string physicalPath = null;
// Url priority: // Url priority:
if (!ssl || (ssl && CdnSupportsSsl)) { //Not ssl or ssl and cdn supports it if (settings.DebugMode) {
if (settings.DebugMode) { url = settings.CdnMode
url = settings.CdnMode ? Coalesce(UrlCdnDebug, UrlDebug, UrlCdn, Url)
? Coalesce(UrlCdnDebug, UrlDebug, UrlCdn, Url) : Coalesce(UrlDebug, Url, UrlCdnDebug, UrlCdn);
: Coalesce(UrlDebug, Url, UrlCdnDebug, UrlCdn);
}
else {
url = settings.CdnMode
? Coalesce(UrlCdn, Url, UrlCdnDebug, UrlDebug)
: Coalesce(Url, UrlDebug, UrlCdn, UrlCdnDebug);
}
} }
else { //ssl and cdn does not support it, only evaluate non-cdn url's else {
url = settings.DebugMode url = settings.CdnMode
? Coalesce(UrlDebug, Url) ? Coalesce(UrlCdn, Url, UrlCdnDebug, UrlDebug)
: Coalesce(Url, UrlDebug); : Coalesce(Url, UrlDebug, UrlCdn, UrlCdnDebug);
} }
if (url == UrlDebug) { if (url == UrlDebug) {
physicalPath = PhysicalPathDebug; physicalPath = PhysicalPathDebug;

View File

@ -1,4 +1,3 @@
using System;
using System.Web.Mvc; using System.Web.Mvc;
namespace Orchard.UI.Resources { namespace Orchard.UI.Resources {
@ -6,16 +5,16 @@ namespace Orchard.UI.Resources {
public ResourceDefinition Resource { get; set; } public ResourceDefinition Resource { get; set; }
public RequireSettings Settings { get; set; } public RequireSettings Settings { get; set; }
public string GetResourceUrl(RequireSettings baseSettings, string appPath, bool ssl, IResourceFileHashProvider resourceFileHashProvider) { public string GetResourceUrl(RequireSettings baseSettings, string appPath, IResourceFileHashProvider resourceFileHashProvider) {
return Resource.ResolveUrl(baseSettings == null ? Settings : baseSettings.Combine(Settings), appPath, ssl, resourceFileHashProvider); return Resource.ResolveUrl(baseSettings == null ? Settings : baseSettings.Combine(Settings), appPath, resourceFileHashProvider);
} }
public TagBuilder GetTagBuilder(RequireSettings baseSettings, string appPath, IResourceFileHashProvider resourceFileHashProvider) { public TagBuilder GetTagBuilder(RequireSettings baseSettings, string appPath, IResourceFileHashProvider resourceFileHashProvider) {
var tagBuilder = new TagBuilder(Resource.TagName); var tagBuilder = new TagBuilder(Resource.TagName);
tagBuilder.MergeAttributes(Resource.TagBuilder.Attributes); tagBuilder.MergeAttributes(Resource.TagBuilder.Attributes);
if (!String.IsNullOrEmpty(Resource.FilePathAttributeName)) { if (!string.IsNullOrEmpty(Resource.FilePathAttributeName)) {
var resolvedUrl = GetResourceUrl(baseSettings, appPath, false, resourceFileHashProvider); var resolvedUrl = GetResourceUrl(baseSettings, appPath, resourceFileHashProvider);
if (!String.IsNullOrEmpty(resolvedUrl)) { if (!string.IsNullOrEmpty(resolvedUrl)) {
tagBuilder.MergeAttribute(Resource.FilePathAttributeName, resolvedUrl, true); tagBuilder.MergeAttribute(Resource.FilePathAttributeName, resolvedUrl, true);
} }
} }