Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
…ng WinHttpHandler
  • Loading branch information
matthid committed Jul 22, 2018
commit 49d7746e007a5b88c71c4145d03d3160cadb3767
364 changes: 270 additions & 94 deletions integrationtests/Paket.IntegrationTests/Paket.IntegrationTests.fsproj

Large diffs are not rendered by default.

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
Copy Markdown
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 .
87 changes: 58 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,63 @@ 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 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
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