src/NuGetGallery.Services/PackageManagement/PackageHelper.cs
/// <summary>
/// If the input uri is http => check if it's a known domain and convert to https.
/// If the input uri is https => leave as is
/// If the input uri is not a valid uri or not http/https => return false
/// </summary>
If the input uri is http => check if it's a known domain and convert to https.
If the input uri is https => leave as is
If the input uri is not a valid uri or not http/https => return false
If the input uri is http = > check if it ' s a known domain and convert to https . If the input uri is https = > leave as is If the input uri is not a valid uri or not http / https = > return false
public static bool TryPrepareUrlForRendering(string uriString, out string readyUriString, bool rewriteAllHttp = false)
        {
            Uri returnUri = null;
            readyUriString = null;
            if (Uri.TryCreate(uriString, UriKind.Absolute, out var uri))
            {
                if (uri.IsHttpProtocol())
                {
                    if (rewriteAllHttp || uri.IsDomainWithHttpsSupport())
                    {
                        returnUri = uri.ToHttps();
                    }
                    else
                    {
                        returnUri = uri;
                    }
                }
                else if (uri.IsHttpsProtocol() || uri.IsHttpProtocol())
                {
                    returnUri = uri;
                }
            }
            if (returnUri != null)
            {
                readyUriString = returnUri.AbsoluteUri;
                return true;
            }
            return false;
        }
public static bool TryPrepareUrlForRendering ( string uriString , out string readyUriString , bool rewriteAllHttp = false ) { Uri returnUri = null ; readyUriString = null ; if ( Uri . TryCreate ( uriString , UriKind . Absolute , out var uri ) ) { if ( uri . IsHttpProtocol ( ) ) { if ( rewriteAllHttp || uri . IsDomainWithHttpsSupport ( ) ) { returnUri = uri . ToHttps ( ) ; } else { returnUri = uri ; } } else if ( uri . IsHttpsProtocol ( ) || uri . IsHttpProtocol ( ) ) { returnUri = uri ; } } if ( returnUri != null ) { readyUriString = returnUri . AbsoluteUri ; return true ; } return false ; }
If the input uri is http => check if it's a known domain and convert to https.
If the input uri is http = > check if it ' s a known domain and convert to https .
uriString
string
string
out
rewriteAllHttp
bool