src/Microsoft.PackageManagement.NuGetProvider/Utility/NuGetPathUtility.cs
/// <summary>
/// Returns the validated uri. Returns null if we cannot validate it
/// </summary>
/// <param name="query"></param>
/// <param name="request"></param>
/// <returns></returns>
Returns the validated uri. Returns null if we cannot validate it
Returns the validated uri . Returns null if we cannot validate it
internal static Uri ValidateUri(Uri query, NuGetRequest request)
        {
            var client = request.ClientWithoutAcceptHeader;
            var response = PathUtility.GetHttpResponse(client, query.AbsoluteUri, (() => request.IsCanceled),
                ((msg, num) => request.Verbose(Resources.Messages.RetryingDownload, msg, num)), (msg) => request.Verbose(msg), (msg) => request.Debug(msg));
            if (response == null)
            {
                return null;
            }
            if (!response.IsSuccessStatusCode)
            {
                if (response.StatusCode == HttpStatusCode.MultipleChoices || response.StatusCode == HttpStatusCode.MovedPermanently
                    || response.StatusCode == HttpStatusCode.Found || response.StatusCode == HttpStatusCode.SeeOther
                    || response.StatusCode == HttpStatusCode.TemporaryRedirect)
                {
                    string location = response.Headers.GetValues("Location").FirstOrDefault();
                    if (String.IsNullOrWhiteSpace(location))
                    {
                        return null;
                    }
                    query = new Uri(location);
                }
                else
                {
                    return null;
                }
            }
            else
            {
                query = new Uri(response.RequestMessage.RequestUri.AbsoluteUri);
            }
            string queryUri = "FoooBarr".MakeFindPackageByIdQuery(PathUtility.UriCombine(query.AbsoluteUri, NuGetConstant.FindPackagesById));
            response = PathUtility.GetHttpResponse(client, queryUri, (() => request.IsCanceled),
                ((msg, num) => request.Verbose(Resources.Messages.RetryingDownload, msg, num)), (msg) => request.Verbose(msg), (msg) => request.Debug(msg));
            if (response == null || !response.IsSuccessStatusCode)
            {
                return null;
            }
            return query;
        }
internal static Uri ValidateUri ( Uri query , NuGetRequest request ) { var client = request . ClientWithoutAcceptHeader ; var response = PathUtility . GetHttpResponse ( client , query . AbsoluteUri , ( ( ) => request . IsCanceled ) , ( ( msg , num ) => request . Verbose ( Resources . Messages . RetryingDownload , msg , num ) ) , ( msg ) => request . Verbose ( msg ) , ( msg ) => request . Debug ( msg ) ) ; if ( response == null ) { return null ; } if ( ! response . IsSuccessStatusCode ) { if ( response . StatusCode == HttpStatusCode . MultipleChoices || response . StatusCode == HttpStatusCode . MovedPermanently || response . StatusCode == HttpStatusCode . Found || response . StatusCode == HttpStatusCode . SeeOther || response . StatusCode == HttpStatusCode . TemporaryRedirect ) { string location = response . Headers . GetValues ( " " ) . FirstOrDefault ( ) ; if ( String . IsNullOrWhiteSpace ( location ) ) { return null ; } query = new Uri ( location ) ; } else { return null ; } } else { query = new Uri ( response . RequestMessage . RequestUri . AbsoluteUri ) ; } string queryUri = " " . MakeFindPackageByIdQuery ( PathUtility . UriCombine ( query . AbsoluteUri , NuGetConstant . FindPackagesById ) ) ; response = PathUtility . GetHttpResponse ( client , queryUri , ( ( ) => request . IsCanceled ) , ( ( msg , num ) => request . Verbose ( Resources . Messages . RetryingDownload , msg , num ) ) , ( msg ) => request . Verbose ( msg ) , ( msg ) => request . Debug ( msg ) ) ; if ( response == null || ! response . IsSuccessStatusCode ) { return null ; } return query ; }
Returns the validated uri.
Returns the validated uri .
// if response is not success, we need to check for redirection // Check for redirection (http status code 3xx) // get the redirected direction // make a new query based on location // other status code is wrong //Making a query like: www.nuget.org/api/v2/FindPackagesById()?id='FoooBarr' to check the server available.  //'FoooBarr' is an any random package id // The link is not valid
None
query
Uri
None
request
NuGetRequest
None