예제 #1
0
        public static Stream GetAssetStream(GitHubAsset asset, string token)
        {
            string proxiedUrl = UpliftPreferences.FromDefaultFile().GetProxiedUrl(asset.apiURL);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(proxiedUrl);

            request.Method = "GET";
            if (!string.IsNullOrEmpty(token))
            {
                request.Headers["Authorization"] = "token " + token;
            }
            request.Accept            = "application/octet-stream";
            request.UserAgent         = "Uplift GithubRepository/1.0 - https://github.com/DragonBox/uplift";
            request.AllowAutoRedirect = false;

            ServicePointManager.ServerCertificateValidationCallback = GitHub.CertificateValidationCallback;
            Uri            address;
            HttpStatusCode responseStatus;

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                responseStatus = response.StatusCode;
                if ((int)response.StatusCode < 300 || (int)response.StatusCode > 399)
                {
                    throw new ApplicationException("Request should be redirected");
                }
                address = new Uri(response.GetResponseHeader("Location"));
            }

            request           = (HttpWebRequest)WebRequest.Create(UpliftPreferences.FromDefaultFile().GetProxiedUrl(address.OriginalString));
            request.Method    = "GET";
            request.UserAgent = "Uplift GithubRepository/1.0 - https://github.com/DragonBox/uplift";
            HttpWebResponse finalResponse = (HttpWebResponse)request.GetResponse();

            responseStatus = finalResponse.StatusCode;
            if ((int)finalResponse.StatusCode >= 200 && (int)finalResponse.StatusCode <= 299)
            {
                return(finalResponse.GetResponseStream());
            }

            throw new ApplicationException("Could not get asset at " + asset.apiURL);
        }
예제 #2
0
 public static Stream GetAssetStream(GitHubAsset asset)
 {
     return(GetAssetStream(asset, ""));
 }