Skip to content

Commit

Permalink
Framework/UI/Resources: Removing ResourceDefinition.CdnSupportsSsl
Browse files Browse the repository at this point in the history
Discussion: #6941
  • Loading branch information
LombiqTechnologies authored and BenedekFarkas committed Aug 29, 2019
1 parent e7bcd91 commit ac11024
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 40 deletions.
7 changes: 4 additions & 3 deletions src/Orchard.Tests/UI/Resources/ResourceManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ private void VerifyPaths(string resourceType, RequireSettings defaultSettings, s
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));
}

Expand Down Expand Up @@ -111,7 +112,7 @@ public void CdnSslPathIsUsedInCdnMode() {
[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);
Expand All @@ -120,7 +121,7 @@ public void LocalPathIsUsedInCdnModeNotSupportsSsl() {
[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);
Expand Down
3 changes: 1 addition & 2 deletions src/Orchard.Web/Core/Shapes/CoreShapes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,11 @@ private void WriteResources(dynamic Display, TextWriter Output, string resourceT
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;
Expand Down
37 changes: 8 additions & 29 deletions src/Orchard/UI/Resources/ResourceDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ public string PhysicalPathDebug {
}

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; }
Expand Down Expand Up @@ -167,17 +165,9 @@ public ResourceDefinition SetCdn(string cdnUrl, string cdnUrlDebug) {

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);
}
Expand Down Expand Up @@ -213,29 +203,18 @@ public ResourceDefinition SetDependencies(params string[] dependencies) {
}

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;
Expand Down
11 changes: 5 additions & 6 deletions src/Orchard/UI/Resources/ResourceRequiredContext.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
using System;
using System.Web.Mvc;

namespace Orchard.UI.Resources {
public class ResourceRequiredContext {
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);
}
}
Expand Down

0 comments on commit ac11024

Please sign in to comment.