private static INuGetResourceCollection GetResourcesImpl(string baseUrl, RequestWrapper request) { INuGetResourceCollection res = null; HttpClient client = request.GetClientWithHeaders(); HttpResponseMessage response = PathUtility.GetHttpResponse(client, baseUrl, (() => request.IsCanceled()), ((msg, num) => request.Verbose(Resources.Messages.RetryingDownload, msg, num)), (msg) => request.Verbose(msg), (msg) => request.Debug(msg)); if (!response.IsSuccessStatusCode) { throw new Exception(Resources.Messages.NuGetEndpointDiscoveryFailed); } string content = new StreamReader(NuGetClient.DownloadDataToStream(baseUrl, request)).ReadToEnd(); // If the response starts with the magic XML header, it's v2 if (content.StartsWith(Constants.XmlStartContent)) { res = NuGetResourceCollection2.Make(baseUrl); } else { try { dynamic root = DynamicJsonParser.Parse(content); string version = root.version; if (version != null && version.StartsWith("3.")) { // v3 feed res = NuGetResourceCollection3.Make(root, baseUrl, request); } } catch (Exception ex) { Exception discoveryException = new Exception(Resources.Messages.NuGetEndpointDiscoveryFailed, ex); throw discoveryException; } } if (res == null) { // Couldn't figure out what this is throw new Exception(Resources.Messages.NuGetEndpointDiscoveryFailed); } return(res); }