12
12
// limitations under the License.
13
13
// ----------------------------------------------------------------------------------
14
14
15
+ using Microsoft . WindowsAzure . Commands . Utilities . Common ;
15
16
using System ;
16
- using System . Threading ;
17
- using System . Threading . Tasks ;
17
+ using System . Collections . Generic ;
18
+ using System . Management . Automation ;
18
19
using System . Net . Http ;
19
- using Microsoft . Azure . Commands . Common . Authentication ;
20
20
using System . Net . Http . Headers ;
21
- using System . Management . Automation ;
21
+ using System . Threading ;
22
+ using System . Threading . Tasks ;
22
23
23
24
namespace Microsoft . Azure . Commands . Common
24
25
{
@@ -30,16 +31,18 @@ namespace Microsoft.Azure.Commands.Common
30
31
/// </summary>
31
32
public class UserAgent
32
33
{
33
- Version _version ;
34
+ private ProductInfoHeaderValue [ ] _userAgents ;
34
35
35
36
public UserAgent ( InvocationInfo invocation )
36
- : this ( invocation ? . MyCommand ? . Module ? . Version ?? new Version ( "1.0.0" ) )
37
37
{
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 ( ) ;
43
46
}
44
47
45
48
/// <summary>
@@ -53,10 +56,7 @@ public UserAgent(Version moduleVersion)
53
56
/// <returns>Amended pipeline for retrieving a response</returns>
54
57
public Task < HttpResponseMessage > SendAsync ( HttpRequestMessage request , CancellationToken token , Action cancel , SignalDelegate signal , NextDelegate next )
55
58
{
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 )
60
60
{
61
61
request . Headers . UserAgent . Add ( userAgent ) ;
62
62
}
0 commit comments