Skip to content

Commit

Permalink
[utils] trying to fix #1873
Browse files Browse the repository at this point in the history
  • Loading branch information
haf committed Aug 24, 2016
1 parent 0146b97 commit ab84035
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/Paket.Core/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,14 @@ let getDefaultProxyFor =

let inline createWebClient (url,auth:Auth option) =
let client = new WebClient()
client.Headers.Add("user-agent", "Paket")
client.Proxy <- getDefaultProxyFor url

let githubToken =
Environment.GetEnvironmentVariable "PAKET_GITHUB_API_TOKEN"

match auth with
| None -> client.UseDefaultCredentials <- true
| Some(Credentials(username, password)) ->
| Some (Credentials(username, password)) ->
// 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
Expand All @@ -344,9 +349,16 @@ let inline createWebClient (url,auth:Auth option) =
//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
client.Headers.Add("user-agent", "Paket")
client.Proxy <- getDefaultProxyFor url

// having this match above lets explicitly configured tokens override environment variables
| Some (Token token) ->
client.Headers.[HttpRequestHeader.Authorization] <- sprintf "token %s" token

| None when githubToken <> null ->
client.Headers.[HttpRequestHeader.Authorization] <- sprintf "token %s" githubToken

| None ->
client.UseDefaultCredentials <- true
client


Expand Down

0 comments on commit ab84035

Please sign in to comment.