Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to cache proxy #1153

Merged
merged 11 commits into from
Oct 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
#### 2.15.9 - 21.10.2015
* USABILITY: If caching fails we should recover - https://github.com/fsprojects/Paket/issues/1152

#### 2.15.8 - 20.10.2015
* Try to report better error when file is blocked by Firewall - https://github.com/fsprojects/Paket/pull/1155

#### 2.15.7 - 20.10.2015
* Check that download http status code was 200

#### 2.15.6 - 19.10.2015
#### 2.16.0-alpha004 - 21.10.2015
* Log Request performance

#### 2.15.5 - 19.10.2015
* Check that download http status code was 200
* Try to report better error when file is blocked by Firewall - https://github.com/fsprojects/Paket/pull/1155
* BUGFIX: Fixed loading of Project files on mono - https://github.com/fsprojects/Paket/pull/1149
* PERFORMANCE: Caching proxy scheme - https://github.com/fsprojects/Paket/pull/1153
* USABILITY: If caching fails we should recover - https://github.com/fsprojects/Paket/issues/1152

#### 2.15.1 - 17.10.2015
* BUGFIX: Fixed framework restriction filter - https://github.com/fsprojects/Paket/pull/1146
Expand Down
8 changes: 4 additions & 4 deletions src/Paket.Bootstrapper/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
[assembly: AssemblyTitleAttribute("Paket.Bootstrapper")]
[assembly: AssemblyProductAttribute("Paket")]
[assembly: AssemblyDescriptionAttribute("A package dependency manager for .NET with support for NuGet packages and GitHub repositories.")]
[assembly: AssemblyVersionAttribute("2.15.9")]
[assembly: AssemblyFileVersionAttribute("2.15.9")]
[assembly: AssemblyInformationalVersionAttribute("2.15.9")]
[assembly: AssemblyVersionAttribute("2.16.0")]
[assembly: AssemblyFileVersionAttribute("2.16.0")]
[assembly: AssemblyInformationalVersionAttribute("2.16.0-alpha004")]
namespace System {
internal static class AssemblyVersionInformation {
internal const string Version = "2.15.9";
internal const string Version = "2.16.0";
}
}
8 changes: 4 additions & 4 deletions src/Paket.Core/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ open System.Reflection
[<assembly: AssemblyProductAttribute("Paket")>]
[<assembly: AssemblyCompanyAttribute("Paket team")>]
[<assembly: AssemblyDescriptionAttribute("A package dependency manager for .NET with support for NuGet packages and GitHub repositories.")>]
[<assembly: AssemblyVersionAttribute("2.15.9")>]
[<assembly: AssemblyFileVersionAttribute("2.15.9")>]
[<assembly: AssemblyInformationalVersionAttribute("2.15.9")>]
[<assembly: AssemblyVersionAttribute("2.16.0")>]
[<assembly: AssemblyFileVersionAttribute("2.16.0")>]
[<assembly: AssemblyInformationalVersionAttribute("2.16.0-alpha004")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] Version = "2.15.9"
let [<Literal>] Version = "2.16.0"
16 changes: 3 additions & 13 deletions src/Paket.Core/NuGetV2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,57 +62,47 @@ let rec private followODataLink auth url =
}



let tryGetAllVersionsFromNugetODataWithFilter (auth, nugetURL, package:PackageName) =
async {
try
let sw = System.Diagnostics.Stopwatch.StartNew()
let url = sprintf "%s/Packages?$filter=Id eq '%O'" nugetURL package
verbosefn "getAllVersionsFromNugetODataWithFilter from url '%s'" url
let! result = followODataLink auth url
traceVerbose <| sprintf "PERF: ODataWithFilter %O: %dms" package sw.ElapsedMilliseconds
return Some result
with _ -> return None
}

let tryGetPackageVersionsViaOData (auth, nugetURL, package:PackageName) =
async {
try
let sw = System.Diagnostics.Stopwatch.StartNew()
let url = sprintf "%s/FindPackagesById()?id='%O'" nugetURL package
verbosefn "getAllVersionsFromNugetOData from url '%s'" url
let! result = followODataLink auth url
traceVerbose <| sprintf "PERF: OData %O: %dms" package sw.ElapsedMilliseconds
return Some result
with _ -> return None
}

let tryGetPackageVersionsViaJson (auth, nugetURL, package:PackageName) =
async {
let sw = System.Diagnostics.Stopwatch.StartNew()
let url = sprintf "%s/package-versions/%O?includePrerelease=true" nugetURL package
let! raw = safeGetFromUrl (auth, url, acceptJson)

match raw with
| None -> return None
| Some data ->
try
traceVerbose <| sprintf "PERF: json %O: %dms" package sw.ElapsedMilliseconds
return Some(JsonConvert.DeserializeObject<string []> data)
with _ -> return None
}

let tryNuGetV3 (auth, nugetV3Url, package:PackageName) =
async {
try
let sw = System.Diagnostics.Stopwatch.StartNew()
async {
try
let! data = NuGetV3.findVersionsForPackage(nugetV3Url, auth, package, true, 100000)
match data with
| Some data when Array.isEmpty data -> return None
| None -> return None
| _ ->
traceVerbose <| sprintf "PERF: V3 %O: %dms" package sw.ElapsedMilliseconds
return data
| _ -> return data
with exn -> return None
}

Expand Down
6 changes: 4 additions & 2 deletions src/Paket.Core/SemVer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type PreRelease =
match yobj with
| :? PreRelease as y -> x.Origin = y.Origin
| _ -> false

override x.ToString() = x.Origin

override x.GetHashCode() = hash x.Origin
interface System.IComparable with
Expand Down Expand Up @@ -171,7 +173,7 @@ module SemVer =
let firstDash = version.IndexOf("-")
let plusIndex = version.IndexOf("+")

let majorMinorPatch =
let majorMinorPatch =
let firstSigil = if firstDash > 0 then firstDash else plusIndex
match firstSigil with
| -1 -> version
Expand All @@ -181,7 +183,7 @@ module SemVer =
match firstDash, plusIndex with
| -1, _ -> ""
| d, p when p = -1 -> version.Substring(d+1)
| d, p -> version.Substring(d+1, (version.Length - 1 - p) )
| d, p -> version.Substring(d+1, (version.Length - 1 - p) )

/// there can only be one piece of build metadata, and it is signified by a + and then any number of dot-separated alphanumeric groups.
/// this just greedily takes the whole remaining string :(
Expand Down
46 changes: 29 additions & 17 deletions src/Paket.Core/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ let envProxies () =
let getEnvValue (name:string) =
let v = Environment.GetEnvironmentVariable(name.ToUpperInvariant())
// under mono, env vars are case sensitive
if v = null then Environment.GetEnvironmentVariable(name.ToLowerInvariant()) else v
if isNull v then Environment.GetEnvironmentVariable(name.ToLowerInvariant()) else v
let bypassList =
let noproxy = getEnvValue "NO_PROXY"
if String.IsNullOrEmpty(noproxy) then [||] else
Expand All @@ -141,7 +141,7 @@ let envProxies () =
let getProxy (scheme:string) =
let envVarName = sprintf "%s_PROXY" (scheme.ToUpperInvariant())
let envVarValue = getEnvValue envVarName
if envVarValue = null then
if isNull envVarValue then
None
else
match Uri.TryCreate(envVarValue, UriKind.Absolute) with
Expand All @@ -159,24 +159,35 @@ let envProxies () =
| _ -> map

[ "http"; "https" ]
|> List.fold addProxy Map.empty
|> List.fold addProxy Map.empty

let calcEnvProxies = lazy (envProxies())

let private proxies = System.Collections.Concurrent.ConcurrentDictionary<_,_>()

let getDefaultProxyFor url =
let uri = new Uri(url)
let getDefault () =
let result = WebRequest.GetSystemWebProxy()
let address = result.GetProxy(uri)

if address = uri then null else
let proxy = new WebProxy(address)
proxy.Credentials <- CredentialCache.DefaultCredentials
proxy.BypassProxyOnLocal <- true
let key = uri.Host,uri.Port,uri.Scheme
match proxies.TryGetValue key with
| true,proxy -> proxy
| _ ->
let getDefault () =
let result = WebRequest.GetSystemWebProxy()
let address = result.GetProxy(uri)

if address = uri then null else
let proxy = new WebProxy(address)
proxy.Credentials <- CredentialCache.DefaultCredentials
proxy.BypassProxyOnLocal <- true
proxy

let proxy =
match calcEnvProxies.Force().TryFind uri.Scheme with
| Some p -> if p.GetProxy(uri) <> uri then p else getDefault()
| None -> getDefault()
proxies.TryAdd(key,proxy) |> ignore
proxy

match envProxies().TryFind uri.Scheme with
| Some p -> if p.GetProxy(uri) <> uri then p else getDefault()
| None -> getDefault()

let inline createWebClient(url,auth:Auth option) =
let client = new WebClient()
match auth with
Expand All @@ -188,7 +199,7 @@ let inline createWebClient(url,auth:Auth option) =
//ONLY after a 401
//client.Credentials <- new NetworkCredential(auth.Username,auth.Password)

//so use THIS instead to send credenatials RIGHT AWAY
//so use THIS instead to send credentials RIGHT AWAY
let credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password))
client.Headers.[HttpRequestHeader.Authorization] <- sprintf "Basic %s" credentials
| Some(Token token) -> client.Headers.[HttpRequestHeader.Authorization] <- sprintf "token %s" token
Expand Down Expand Up @@ -253,12 +264,13 @@ let getXmlFromUrl (auth:Auth option, url : string) =
let safeGetFromUrl (auth:Auth option, url : string, contentType : string) =
async {
try
let uri = Uri(url)
use client = createWebClient(url,auth)

if notNullOrEmpty contentType then
client.Headers.Add(HttpRequestHeader.Accept, contentType)

let s = client.DownloadStringTaskAsync(Uri(url)) |> Async.AwaitTask
let s = client.DownloadStringTaskAsync(uri) |> Async.AwaitTask
let! raw = s
return Some raw
with _ -> return None
Expand Down
8 changes: 4 additions & 4 deletions src/Paket.PowerShell/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ open System.Reflection
[<assembly: AssemblyProductAttribute("Paket")>]
[<assembly: AssemblyCompanyAttribute("Paket team")>]
[<assembly: AssemblyDescriptionAttribute("A package dependency manager for .NET with support for NuGet packages and GitHub repositories.")>]
[<assembly: AssemblyVersionAttribute("2.15.9")>]
[<assembly: AssemblyFileVersionAttribute("2.15.9")>]
[<assembly: AssemblyInformationalVersionAttribute("2.15.9")>]
[<assembly: AssemblyVersionAttribute("2.16.0")>]
[<assembly: AssemblyFileVersionAttribute("2.16.0")>]
[<assembly: AssemblyInformationalVersionAttribute("2.16.0-alpha004")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] Version = "2.15.9"
let [<Literal>] Version = "2.16.0"
8 changes: 4 additions & 4 deletions src/Paket/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ open System.Reflection
[<assembly: AssemblyProductAttribute("Paket")>]
[<assembly: AssemblyCompanyAttribute("Paket team")>]
[<assembly: AssemblyDescriptionAttribute("A package dependency manager for .NET with support for NuGet packages and GitHub repositories.")>]
[<assembly: AssemblyVersionAttribute("2.15.9")>]
[<assembly: AssemblyFileVersionAttribute("2.15.9")>]
[<assembly: AssemblyInformationalVersionAttribute("2.15.9")>]
[<assembly: AssemblyVersionAttribute("2.16.0")>]
[<assembly: AssemblyFileVersionAttribute("2.16.0")>]
[<assembly: AssemblyInformationalVersionAttribute("2.16.0-alpha004")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] Version = "2.15.9"
let [<Literal>] Version = "2.16.0"
2 changes: 1 addition & 1 deletion src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<StartArguments>update group Build</StartArguments>
<StartArguments>pack output D:\code\paketbug\output</StartArguments>
<StartArguments>install</StartArguments>
<StartArguments>update -f</StartArguments>
<StartArguments>update</StartArguments>
<StartAction>Project</StartAction>
<StartProgram>paket.exe</StartProgram>
<StartWorkingDirectory>c:\code\Paketkopie</StartWorkingDirectory>
Expand Down
25 changes: 25 additions & 0 deletions tests/Paket.Tests/SemVerSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,31 @@ let ``can normalize CI versions in prerelease``() =
let ``should parse very large prerelease numbers (aka timestamps)``() =
(SemVer.Parse "0.22.0-pre20150223185624").Normalize() |> shouldEqual "0.22.0-pre20150223185624"

[<Test>]
let ``should parse paket prerelease versions``() =
let v = SemVer.Parse "1.2.3-alpha002"

v.Major |> shouldEqual 1u
v.Minor |> shouldEqual 2u
v.Patch |> shouldEqual 3u
v.PreRelease.Value.ToString() |> shouldEqual "alpha002"
v.PreRelease.Value.Name |> shouldEqual "alpha"


[<Test>]
let ``should parse CoreClr prerelease versions``() =
let v = SemVer.Parse "1.2.3-beta-22819"

v.Major |> shouldEqual 1u
v.Minor |> shouldEqual 2u
v.Patch |> shouldEqual 3u
v.PreRelease.Value.ToString() |> shouldEqual "beta-22819"
v.PreRelease.Value.Name |> shouldEqual "beta"

[<Test>]
let ``should compare CoreClr prerelease versions``() =
(SemVer.Parse "1.2.3-beta-22819") |> shouldBeGreaterThan (SemVer.Parse "1.2.3-beta-22818")
(SemVer.Parse "1.2.3-beta-22817") |> shouldBeSmallerThan (SemVer.Parse "1.2.3-beta-22818")

[<Test>]
let ``version core elements must be non-negative (SemVer 2.0.0/2)`` () =
Expand Down