Skip to content

Commit

Permalink
paket.bootstrapper.exe and paket.exe use better proxy detection - ref…
Browse files Browse the repository at this point in the history
…erences #552
  • Loading branch information
forki committed Jan 15, 2015
1 parent 4d641c5 commit 59cc8d5
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/Paket.Bootstrapper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/Paket.Core/ConfigFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/NuGetV2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/PackageSources.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions src/Paket.Core/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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 ->
Expand All @@ -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 ->
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/Paket.Core/VSIntegration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 59cc8d5

Please sign in to comment.