Skip to content

Commit e929c55

Browse files
authored
Update userAgent of autogen cmdlet (#15939)
1 parent a7cb13d commit e929c55

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/Accounts/Accounts/CommonModule/UserAgent.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
1516
using System;
16-
using System.Threading;
17-
using System.Threading.Tasks;
17+
using System.Collections.Generic;
18+
using System.Management.Automation;
1819
using System.Net.Http;
19-
using Microsoft.Azure.Commands.Common.Authentication;
2020
using System.Net.Http.Headers;
21-
using System.Management.Automation;
21+
using System.Threading;
22+
using System.Threading.Tasks;
2223

2324
namespace Microsoft.Azure.Commands.Common
2425
{
@@ -30,16 +31,18 @@ namespace Microsoft.Azure.Commands.Common
3031
/// </summary>
3132
public class UserAgent
3233
{
33-
Version _version;
34+
private ProductInfoHeaderValue[] _userAgents;
3435

3536
public UserAgent(InvocationInfo invocation)
36-
: this(invocation?.MyCommand?.Module?.Version ?? new Version("1.0.0"))
3737
{
38-
}
39-
40-
public UserAgent(Version moduleVersion)
41-
{
42-
_version = moduleVersion;
38+
List<ProductInfoHeaderValue> list = new List<ProductInfoHeaderValue>();
39+
string azVersion = (String.IsNullOrWhiteSpace(AzurePSCmdlet.AzVersion)) ? "0.0.0" : AzurePSCmdlet.AzVersion;
40+
list.Add(new ProductInfoHeaderValue("AzurePowershell", $"v{azVersion}"));
41+
if(!String.IsNullOrWhiteSpace(AzurePSCmdlet.PowerShellVersion))
42+
{
43+
list.Add(new ProductInfoHeaderValue("PSVersion", $"v{AzurePSCmdlet.PowerShellVersion}"));
44+
}
45+
_userAgents = list.ToArray();
4346
}
4447

4548
/// <summary>
@@ -53,10 +56,7 @@ public UserAgent(Version moduleVersion)
5356
/// <returns>Amended pipeline for retrieving a response</returns>
5457
public Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken token, Action cancel, SignalDelegate signal, NextDelegate next)
5558
{
56-
var userAgents = new ProductInfoHeaderValue[] { new ProductInfoHeaderValue("AzurePowershell", $"Az4.0.0-preview") };
57-
// add user agent headers
58-
59-
foreach (var userAgent in userAgents)
59+
foreach (var userAgent in _userAgents)
6060
{
6161
request.Headers.UserAgent.Add(userAgent);
6262
}

0 commit comments

Comments
 (0)