mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-25 19:17:13 +08:00
committed by
Sébastien Ros
parent
ebd731e70a
commit
dcca575fc3
@@ -31,9 +31,13 @@ namespace Orchard.Tests.UI.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void VerifyPaths(string resourceType, RequireSettings defaultSettings, string expectedPaths) {
|
private void VerifyPaths(string resourceType, RequireSettings defaultSettings, string expectedPaths) {
|
||||||
|
VerifyPaths(resourceType, defaultSettings, expectedPaths, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
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)).ToArray());
|
var renderedResources = string.Join(",", requiredResources.Select(context => context.GetResourceUrl(defaultSettings, _appPath, ssl)).ToArray());
|
||||||
Assert.That(renderedResources, Is.EqualTo(expectedPaths));
|
Assert.That(renderedResources, Is.EqualTo(expectedPaths));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +96,33 @@ namespace Orchard.Tests.UI.Resources {
|
|||||||
VerifyPaths("script", new RequireSettings { CdnMode = true }, "http://cdn/script1.min.js");
|
VerifyPaths("script", new RequireSettings { CdnMode = true }, "http://cdn/script1.min.js");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CdnSslPathIsUsedInCdnMode() {
|
||||||
|
_testManifest.DefineManifest = m => {
|
||||||
|
m.DefineResource("script", "Script1").SetUrl("script1.js").SetCdn("https://cdn/script1.min.js");
|
||||||
|
};
|
||||||
|
_resourceManager.Require("script", "Script1");
|
||||||
|
VerifyPaths("script", new RequireSettings { CdnMode = true }, "https://cdn/script1.min.js", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[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);
|
||||||
|
};
|
||||||
|
_resourceManager.Require("script", "Script1");
|
||||||
|
VerifyPaths("script", new RequireSettings { CdnMode = true }, "script1.min.js", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[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);
|
||||||
|
};
|
||||||
|
_resourceManager.Require("script", "Script1");
|
||||||
|
VerifyPaths("script", new RequireSettings { CdnMode = true, DebugMode = true }, "script1.js", true);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void CdnDebugPathIsUsedInCdnModeAndDebugMode() {
|
public void CdnDebugPathIsUsedInCdnModeAndDebugMode() {
|
||||||
_testManifest.DefineManifest = m => {
|
_testManifest.DefineManifest = m => {
|
||||||
|
|||||||
@@ -455,12 +455,12 @@ 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?.Request?.IsSecureConnection ?? false;
|
||||||
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 path = context.GetResourceUrl(defaultSettings, appPath);
|
var path = context.GetResourceUrl(defaultSettings, appPath, ssl);
|
||||||
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;
|
||||||
|
|||||||
@@ -152,6 +152,9 @@ namespace Orchard.UI.Resources {
|
|||||||
if (cdnSupportsSsl.HasValue) {
|
if (cdnSupportsSsl.HasValue) {
|
||||||
CdnSupportsSsl = cdnSupportsSsl.Value;
|
CdnSupportsSsl = cdnSupportsSsl.Value;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
CdnSupportsSsl = cdnUrl.StartsWith("https", StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,20 +178,31 @@ namespace Orchard.UI.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public string ResolveUrl(RequireSettings settings, string applicationPath) {
|
public string ResolveUrl(RequireSettings settings, string applicationPath) {
|
||||||
|
return ResolveUrl(settings, applicationPath, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ResolveUrl(RequireSettings settings, string applicationPath, bool ssl) {
|
||||||
string url;
|
string url;
|
||||||
if (_urlResolveCache.TryGetValue(settings, out url)) {
|
if (_urlResolveCache.TryGetValue(settings, out url)) {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
// Url priority:
|
// Url priority:
|
||||||
if (settings.DebugMode) {
|
if (!ssl || (ssl && CdnSupportsSsl)) { //Not ssl or ssl and cdn supports it
|
||||||
url = settings.CdnMode
|
if (settings.DebugMode) {
|
||||||
? Coalesce(UrlCdnDebug, UrlDebug, UrlCdn, Url)
|
url = settings.CdnMode
|
||||||
: Coalesce(UrlDebug, Url, UrlCdnDebug, UrlCdn);
|
? Coalesce(UrlCdnDebug, UrlDebug, UrlCdn, Url)
|
||||||
|
: Coalesce(UrlDebug, Url, UrlCdnDebug, UrlCdn);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
url = settings.CdnMode
|
||||||
|
? Coalesce(UrlCdn, Url, UrlCdnDebug, UrlDebug)
|
||||||
|
: Coalesce(Url, UrlDebug, UrlCdn, UrlCdnDebug);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else { //ssl and cdn does not support it, only evaluate non-cdn url's
|
||||||
url = settings.CdnMode
|
url = settings.DebugMode
|
||||||
? Coalesce(UrlCdn, Url, UrlCdnDebug, UrlDebug)
|
? Coalesce(UrlDebug, Url)
|
||||||
: Coalesce(Url, UrlDebug, UrlCdn, UrlCdnDebug);
|
: Coalesce(Url, UrlDebug);
|
||||||
}
|
}
|
||||||
if (String.IsNullOrEmpty(url)) {
|
if (String.IsNullOrEmpty(url)) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ 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) {
|
public string GetResourceUrl(RequireSettings baseSettings, string appPath, bool ssl) {
|
||||||
return Resource.ResolveUrl(baseSettings == null ? Settings : baseSettings.Combine(Settings), appPath);
|
return Resource.ResolveUrl(baseSettings == null ? Settings : baseSettings.Combine(Settings), appPath, ssl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TagBuilder GetTagBuilder(RequireSettings baseSettings, string appPath) {
|
public TagBuilder GetTagBuilder(RequireSettings baseSettings, string appPath) {
|
||||||
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);
|
var resolvedUrl = GetResourceUrl(baseSettings, appPath, false);
|
||||||
if (!String.IsNullOrEmpty(resolvedUrl)) {
|
if (!String.IsNullOrEmpty(resolvedUrl)) {
|
||||||
tagBuilder.MergeAttribute(Resource.FilePathAttributeName, resolvedUrl, true);
|
tagBuilder.MergeAttribute(Resource.FilePathAttributeName, resolvedUrl, true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user