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) {
defaultSettings = defaultSettings ?? new RequireSettings();
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));
}
@ -111,7 +112,7 @@ namespace Orchard.Tests.UI.Resources {
[Test]
public void LocalPathIsUsedInCdnModeNotSupportsSsl() {
_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");
VerifyPaths("script", new RequireSettings { CdnMode = true }, "script1.min.js", true);
@ -120,7 +121,7 @@ namespace Orchard.Tests.UI.Resources {
[Test]
public void LocalDebugPathIsUsedInCdnModeNotSupportsSslAndDebug() {
_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");
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
? null
: httpContext.Request.ApplicationPath;
var ssl = httpContext != null && httpContext.Request != null && httpContext.Request.IsSecureConnection;
foreach (var context in requiredResources.Where(r =>
(includeLocation.HasValue ? r.Settings.Location == includeLocation.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 attributes = context.Settings.HasAttributes ? context.Settings.Attributes : null;
IHtmlString result;

View File

@ -120,8 +120,6 @@ namespace Orchard.UI.Resources {
}
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 string FilePathAttributeName { get; private set; }
public TagBuilder TagBuilder { get; private set; }
@ -167,17 +165,9 @@ namespace Orchard.UI.Resources {
if (!string.IsNullOrWhiteSpace(cdnUrlDebug)) UrlCdnDebug = cdnUrlDebug;
else {
CdnSupportsSsl = cdnUrl.StartsWith("https", StringComparison.OrdinalIgnoreCase);
}
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) {
return SetPhysicalPath(physicalPath, null);
}
@ -213,29 +203,18 @@ namespace Orchard.UI.Resources {
}
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 physicalPath = null;
// Url priority:
if (!ssl || (ssl && CdnSupportsSsl)) { //Not ssl or ssl and cdn supports it
if (settings.DebugMode) {
url = settings.CdnMode
? Coalesce(UrlCdnDebug, UrlDebug, UrlCdn, Url)
: Coalesce(UrlDebug, Url, UrlCdnDebug, UrlCdn);
}
else {
url = settings.CdnMode
? Coalesce(UrlCdn, Url, UrlCdnDebug, UrlDebug)
: Coalesce(Url, UrlDebug, UrlCdn, UrlCdnDebug);
}
if (settings.DebugMode) {
url = settings.CdnMode
? Coalesce(UrlCdnDebug, UrlDebug, UrlCdn, Url)
: Coalesce(UrlDebug, Url, UrlCdnDebug, UrlCdn);
}
else { //ssl and cdn does not support it, only evaluate non-cdn url's
url = settings.DebugMode
? Coalesce(UrlDebug, Url)
: Coalesce(Url, UrlDebug);
else {
url = settings.CdnMode
? Coalesce(UrlCdn, Url, UrlCdnDebug, UrlDebug)
: Coalesce(Url, UrlDebug, UrlCdn, UrlCdnDebug);
}
if (url == UrlDebug) {
physicalPath = PhysicalPathDebug;

View File

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