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

Revert impact of https://github.com/dotnet/corefx/issues/31098 by using WinHttpHandler #3307

Merged
merged 8 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from 5 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
364 changes: 270 additions & 94 deletions integrationtests/Paket.IntegrationTests/Paket.IntegrationTests.fsproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1' Or $(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3' Or $(TargetFrameworkVersion) == 'v4.7' Or $(TargetFrameworkVersion) == 'v4.7.1')">
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1' Or $(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3' Or $(TargetFrameworkVersion) == 'v4.7' Or $(TargetFrameworkVersion) == 'v4.7.1') Or $(TargetFrameworkVersion) == 'v4.7.2')">
<ItemGroup>
<Reference Include="Dapper">
<HintPath>..\..\packages\Dapper\lib\net45\Dapper.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
</Reference>
</ItemGroup>
</When>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1' Or $(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3' Or $(TargetFrameworkVersion) == 'v4.7' Or $(TargetFrameworkVersion) == 'v4.7.1')">
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6' Or $(TargetFrameworkVersion) == 'v4.6.1' Or $(TargetFrameworkVersion) == 'v4.6.2' Or $(TargetFrameworkVersion) == 'v4.6.3' Or $(TargetFrameworkVersion) == 'v4.7' Or $(TargetFrameworkVersion) == 'v4.7.1') Or $(TargetFrameworkVersion) == 'v4.7.2')">
<ItemGroup>
<Reference Include="Dapper">
<HintPath>..\..\packages\Dapper\lib\net45\Dapper.dll</HintPath>
Expand Down
1 change: 1 addition & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ nuget FSharp.Compiler.Tools

nuget NETStandard.Library >= 2.0 prerelease
nuget Microsoft.NETCore.App >= 2.0 prerelease
nuget System.Net.Http.WinHttpHandler

nuget Moq
nuget FSCheck
Expand Down
169 changes: 90 additions & 79 deletions paket.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Paket.Core.preview3/Paket.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<PaketCoreSourcesDir>..\Paket.Core</PaketCoreSourcesDir>
<DefineConstants>NO_BOOTSTRAPPER;NO_CONFIGURATIONMANAGER;CUSTOM_WEBPROXY;$(DefineConstants)</DefineConstants>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paket added this, maybe mono doesn't like that

</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\paket-files\fsprojects\FSharp.TypeProviders.SDK\src\AssemblyReader.fs">
Expand Down
1 change: 1 addition & 0 deletions src/Paket.Core.preview3/paket.references
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Newtonsoft.Json
Mono.Cecil
Chessie
System.Security.Cryptography.ProtectedData
System.Net.Http.WinHttpHandler

File:Globbing.fs .
File:AssemblyReader.fs .
89 changes: 60 additions & 29 deletions src/Paket.Core/Common/NetUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ open Paket.Logging
open Paket.Constants
open Chessie.ErrorHandling
open Paket.Domain
open Paket.Utils
open FSharp.Polyfill

open System.Net.Http
Expand Down Expand Up @@ -341,35 +342,65 @@ let internal addHeader (client:HttpClient) (headerKey:string) (headerVal:string)
client.DefaultRequestHeaders.Add(headerKey, headerVal)

let createHttpClient (url,auth:Auth option) =
let handler =
new HttpClientHandler(
UseProxy = true,
Proxy = getDefaultProxyFor url)
handler.AutomaticDecompression <- DecompressionMethods.GZip ||| DecompressionMethods.Deflate

let client = new HttpClient(handler)
match auth with
| None -> handler.UseDefaultCredentials <- true
| Some(Credentials({Username = username; Password = password; Type = AuthType.Basic})) ->
// htttp://stackoverflow.com/questions/16044313/webclient-httpwebrequest-with-basic-authentication-returns-404-not-found-for-v/26016919#26016919
//this works ONLY if the server returns 401 first
//client DOES NOT send credentials on first request
//ONLY after a 401
//client.Credentials <- new NetworkCredential(auth.Username,auth.Password)

//so use THIS instead to send credentials RIGHT AWAY
let credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password))
client.DefaultRequestHeaders.Authorization <-
new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", credentials)
| Some(Credentials({Username = username; Password = password; Type = AuthType.NTLM})) ->
let cred = System.Net.NetworkCredential(username,password)
handler.Credentials <- cred.GetCredential(new Uri(url), "NTLM")
| Some(Token token) ->
client.DefaultRequestHeaders.Authorization <-
new System.Net.Http.Headers.AuthenticationHeaderValue("token", token)
client.DefaultRequestHeaders.Add("user-agent", "Paket")
handler.UseProxy <- true
client
#if !NO_WINCLIENTHANDLER
if isWindows then
// See https://github.com/dotnet/corefx/issues/31098
let proxy = getDefaultProxyFor url
let handler = new WinHttpHandler(Proxy = proxy)
handler.AutomaticDecompression <- DecompressionMethods.GZip ||| DecompressionMethods.Deflate

let client = new HttpClient(handler)
match auth with
| None -> handler.ServerCredentials <- CredentialCache.DefaultCredentials
| Some(Credentials({Username = username; Password = password; Type = AuthType.Basic})) ->
// see lengthy comment below.
let credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password))
client.DefaultRequestHeaders.Authorization <-
new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", credentials)
| Some(Credentials({Username = username; Password = password; Type = AuthType.NTLM})) ->
let cred = System.Net.NetworkCredential(username,password)
handler.ServerCredentials <- cred.GetCredential(new Uri(url), "NTLM")
| Some(Token token) ->
client.DefaultRequestHeaders.Authorization <-
new System.Net.Http.Headers.AuthenticationHeaderValue("token", token)
client.DefaultRequestHeaders.Add("user-agent", "Paket")
// from https://github.com/dotnet/corefx/blob/b6b9a1ad24339266a27fef826233dbbe192cf254/src/System.Net.Http/src/System/Net/Http/HttpClientHandler.Windows.cs#L454-L477
if isNull handler.Proxy then
handler.WindowsProxyUsePolicy <- WindowsProxyUsePolicy.UseWinInetProxy
else
handler.WindowsProxyUsePolicy <- WindowsProxyUsePolicy.UseCustomProxy
client
else
#endif
let handler =
new HttpClientHandler(
UseProxy = true,
Proxy = getDefaultProxyFor url)
handler.AutomaticDecompression <- DecompressionMethods.GZip ||| DecompressionMethods.Deflate

let client = new HttpClient(handler)
match auth with
| None -> handler.UseDefaultCredentials <- true
| Some(Credentials({Username = username; Password = password; Type = AuthType.Basic})) ->
// http://stackoverflow.com/questions/16044313/webclient-httpwebrequest-with-basic-authentication-returns-404-not-found-for-v/26016919#26016919
//this works ONLY if the server returns 401 first
//client DOES NOT send credentials on first request
//ONLY after a 401
//client.Credentials <- new NetworkCredential(auth.Username,auth.Password)

//so use THIS instead to send credentials RIGHT AWAY
let credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password))
client.DefaultRequestHeaders.Authorization <-
new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", credentials)
| Some(Credentials({Username = username; Password = password; Type = AuthType.NTLM})) ->
let cred = System.Net.NetworkCredential(username,password)
handler.Credentials <- cred.GetCredential(new Uri(url), "NTLM")
| Some(Token token) ->
client.DefaultRequestHeaders.Authorization <-
new System.Net.Http.Headers.AuthenticationHeaderValue("token", token)
client.DefaultRequestHeaders.Add("user-agent", "Paket")
handler.UseProxy <- true
client

#if USE_WEB_CLIENT_FOR_UPLOAD
type CustomTimeoutWebClient(timeout) =
Expand Down
Loading