Permalink
Browse files

More reliable way of resolving SSL mode

  • Loading branch information...
muratcakir committed Oct 18, 2018
1 parent 52e6060 commit 000ed272e7870ef6d2a313fbef278cbf239d0363
Showing with 29 additions and 9 deletions.
  1. +29 −9 src/Libraries/SmartStore.Core/Extensions/HttpExtensions.cs
@@ -13,13 +13,21 @@
using System.Web.Mvc;

namespace SmartStore
{
public static class HttpExtensions
{
private const string HTTP_CLUSTER_VAR = "HTTP_CLUSTER_HTTPS";
private const string HTTP_XFWDPROTO_VAR = "HTTP_X_FORWARDED_PROTO";
{
public static class HttpExtensions
{
private const string CACHE_REGION_NAME = "SmartStoreNET:";

private static readonly List<Tuple<string, string>> _sslHeaders = new List<Tuple<string, string>>
{
new Tuple<string, string>("HTTP_CLUSTER_HTTPS", "on"),
new Tuple<string, string>("X-Forwarded-Proto", "https"),
new Tuple<string, string>("x-arr-ssl", null),
new Tuple<string, string>("X-Forwarded-Protocol", "https"),
new Tuple<string, string>("X-Forwarded-Ssl", "on"),
new Tuple<string, string>("X-Url-Scheme", "https")
};

/// <summary>
/// Gets a value which indicates whether the HTTP connection uses secure sockets (HTTPS protocol).
/// Works with Cloud's load balancers.
@@ -28,10 +36,22 @@ public static class HttpExtensions
/// <returns></returns>
public static bool IsSecureConnection(this HttpRequestBase request)
{
return (request.IsSecureConnection
|| (request.ServerVariables[HTTP_CLUSTER_VAR] != null || request.ServerVariables[HTTP_CLUSTER_VAR] == "on")
|| (request.ServerVariables[HTTP_XFWDPROTO_VAR] != null || request.ServerVariables[HTTP_XFWDPROTO_VAR] == "https"));
}
if (request.IsSecureConnection)
{
return true;
}

foreach (var tuple in _sslHeaders)
{
var serverVar = request.ServerVariables[tuple.Item1];
if (serverVar != null)
{
return tuple.Item2 == null || tuple.Item2.Equals(serverVar, StringComparison.OrdinalIgnoreCase);
}
}

return false;
}


/// <summary>

0 comments on commit 000ed27

Please sign in to comment.