diff --git a/src/Paket.Bootstrapper/Program.cs b/src/Paket.Bootstrapper/Program.cs index e2f153aa7b..f22af39b54 100644 --- a/src/Paket.Bootstrapper/Program.cs +++ b/src/Paket.Bootstrapper/Program.cs @@ -11,10 +11,10 @@ class Program static IWebProxy GetDefaultWebProxyFor(String url) { IWebProxy result = WebRequest.GetSystemWebProxy(); - Uri relevantDestination = new Uri(url); - Uri address = result.GetProxy(relevantDestination); + Uri uri = new Uri(url); + Uri address = result.GetProxy(uri); - if (address == relevantDestination) + if (address == uri) return null; return new WebProxy(address) { diff --git a/src/Paket.Core/ConfigFile.fs b/src/Paket.Core/ConfigFile.fs index e79857357d..f253ad5391 100644 --- a/src/Paket.Core/ConfigFile.fs +++ b/src/Paket.Core/ConfigFile.fs @@ -100,10 +100,10 @@ let private setCredentials (username : string) (password : string) (node : XmlEl /// Check if the provided credentials for a specific source are correct -let checkCredentials(source, cred) = - let client = Utils.createWebClient cred +let checkCredentials(url, cred) = + let client = Utils.createWebClient(url,cred) try - client.DownloadData(Uri(source)) |> ignore + client.DownloadData(Uri(url)) |> ignore true with _ -> false diff --git a/src/Paket.Core/NuGetV2.fs b/src/Paket.Core/NuGetV2.fs index c112eded77..d054117bb1 100644 --- a/src/Paket.Core/NuGetV2.fs +++ b/src/Paket.Core/NuGetV2.fs @@ -387,7 +387,7 @@ let DownloadPackage(root, auth, url, name, version:SemVerInfo, force) = let credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(auth.Username + ":" + auth.Password)) request.Headers.[HttpRequestHeader.Authorization] <- String.Format("Basic {0}", credentials) - request.Proxy <- Utils.defaultProxy + request.Proxy <- Utils.getDefaultProxyFor url use! httpResponse = request.AsyncGetResponse() use httpResponseStream = httpResponse.GetResponseStream() diff --git a/src/Paket.Core/PackageSources.fs b/src/Paket.Core/PackageSources.fs index 7fb194d34b..6f703bd602 100644 --- a/src/Paket.Core/PackageSources.fs +++ b/src/Paket.Core/PackageSources.fs @@ -97,7 +97,7 @@ type PackageSource = static member warnIfNoConnection (source,_) = match source with | Nuget {Url = url; Authentication = auth} -> - use client = Utils.createWebClient (auth |> Option.map toBasicAuth) + use client = Utils.createWebClient(url, auth |> Option.map toBasicAuth) try client.DownloadData url |> ignore with _ -> traceWarnfn "Unable to ping remote Nuget feed: %s." url diff --git a/src/Paket.Core/Utils.fs b/src/Paket.Core/Utils.fs index 997241a5a8..0fa703aa5e 100644 --- a/src/Paket.Core/Utils.fs +++ b/src/Paket.Core/Utils.fs @@ -70,18 +70,18 @@ let inline normalizeXml(doc:XmlDocument) = xmlTextWriter.Flush() stringWriter.GetStringBuilder().ToString() -let defaultProxy = +let getDefaultProxyFor url = let result = WebRequest.GetSystemWebProxy() - let irrelevantDestination = new Uri(@"http://google.com") - let address = result.GetProxy(irrelevantDestination) + let uri = new Uri(url) + let address = result.GetProxy(uri) - if address = irrelevantDestination then null else + if address = uri then null else let proxy = new WebProxy(address) proxy.Credentials <- CredentialCache.DefaultCredentials proxy.BypassProxyOnLocal <- true proxy -let inline createWebClient(auth:Auth option) = +let inline createWebClient(url,auth:Auth option) = let client = new WebClient() match auth with | None -> client.UseDefaultCredentials <- true @@ -97,7 +97,7 @@ let inline createWebClient(auth:Auth option) = client.Headers.[HttpRequestHeader.Authorization] <- String.Format("Basic {0}", credentials) client.Headers.Add("user-agent", "Paket") - client.Proxy <- defaultProxy + client.Proxy <- getDefaultProxyFor url client @@ -134,7 +134,7 @@ type System.Net.WebClient with let downloadFromUrl (auth:Auth option, url : string) (filePath: string) = async { try - use client = createWebClient auth + use client = createWebClient(url,auth) do! client.AsyncDownloadFile(Uri(url), filePath) with | exn -> @@ -145,7 +145,7 @@ let downloadFromUrl (auth:Auth option, url : string) (filePath: string) = let getFromUrl (auth:Auth option, url : string) = async { try - use client = createWebClient auth + use client = createWebClient(url,auth) return! client.AsyncDownloadString(Uri(url)) with | exn -> @@ -157,7 +157,7 @@ let getFromUrl (auth:Auth option, url : string) = let safeGetFromUrl (auth:Auth option, url : string) = async { try - use client = createWebClient auth + use client = createWebClient(url,auth) let! raw = client.AsyncDownloadString(Uri(url)) return Some raw with _ -> return None diff --git a/src/Paket.Core/VSIntegration.fs b/src/Paket.Core/VSIntegration.fs index 400d5a3a0d..3b52b273f1 100644 --- a/src/Paket.Core/VSIntegration.fs +++ b/src/Paket.Core/VSIntegration.fs @@ -17,18 +17,21 @@ let private getLatestVersionFromJson (data : string) = let InitAutoRestore environment = let exeDir = Path.Combine(environment.RootDirectory.FullName, ".paket") - use client = createWebClient None + + use client = createWebClient("https://github.com",None) let download version file = rop { do! createDir(exeDir) let fileName = Path.Combine(exeDir, file) let url = sprintf "https://github.com/fsprojects/Paket/releases/download/%s/%s" (string version) file + do! downloadFileSync url fileName client } rop { let releasesUrl = "https://api.github.com/repos/fsprojects/Paket/releases"; + let! data = client |> downloadStringSync releasesUrl let! latestVersion = getLatestVersionFromJson data