Skip to content

Commit 0826839

Browse files
committed
Add 10 minute timeout to HTTPClient (#1626)
1 parent f3d76eb commit 0826839

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

src/code/NuGetServerAPICalls.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public NuGetServerAPICalls (PSRepositoryInfo repository, PSCmdlet cmdletPassedIn
4040
};
4141

4242
_sessionClient = new HttpClient(handler);
43+
_sessionClient.Timeout = TimeSpan.FromMinutes(10);
4344
_sessionClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", userAgentString);
4445
}
4546

src/code/ServerApiCall.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Net;
99
using System.Runtime.ExceptionServices;
1010
using System.Management.Automation;
11+
using System;
1112

1213
namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
1314
{
@@ -30,7 +31,21 @@ public ServerApiCall(PSRepositoryInfo repository, NetworkCredential networkCrede
3031
Credentials = networkCredential
3132
};
3233

33-
_sessionClient = new HttpClient(handler);
34+
if (token)
35+
{
36+
string credString = string.Format(":{0}", networkCredential.Password);
37+
byte[] byteArray = Encoding.ASCII.GetBytes(credString);
38+
39+
_sessionClient = new HttpClient(handler);
40+
_sessionClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
41+
} else {
42+
43+
handler.Credentials = networkCredential;
44+
45+
_sessionClient = new HttpClient(handler);
46+
};
47+
_sessionClient.Timeout = TimeSpan.FromMinutes(10);
48+
3449
}
3550

3651
#endregion

src/code/V2ServerAPICalls.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public V2ServerAPICalls (PSRepositoryInfo repository, PSCmdlet cmdletPassedIn, N
5858
};
5959

6060
_sessionClient = new HttpClient(handler);
61+
_sessionClient.Timeout = TimeSpan.FromMinutes(10);
6162
_sessionClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", userAgentString);
6263
var repoURL = repository.Uri.ToString().ToLower();
6364
_isADORepo = repoURL.Contains("pkgs.dev.azure.com") || repoURL.Contains("pkgs.visualstudio.com");

src/code/V3ServerAPICalls.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public V3ServerAPICalls(PSRepositoryInfo repository, PSCmdlet cmdletPassedIn, Ne
5757
};
5858

5959
_sessionClient = new HttpClient(handler);
60+
_sessionClient.Timeout = TimeSpan.FromMinutes(10);
6061
_sessionClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", userAgentString);
6162

6263
_isNuGetRepo = String.Equals(Repository.Uri.AbsoluteUri, nugetRepoUri, StringComparison.InvariantCultureIgnoreCase);

0 commit comments

Comments
 (0)