From 6bc50d485de949c0325c949c4d618492f5d185c4 Mon Sep 17 00:00:00 2001 From: markekraus Date: Thu, 21 Sep 2017 04:12:09 -0500 Subject: [PATCH 1/7] Add ResponseHeadersVariable to Invoke-RestMethod --- .../WebCmdlet/Common/InvokeRestMethodCommand.Common.cs | 7 +++++++ .../WebCmdlet/CoreCLR/InvokeRestMethodCommand.CoreClr.cs | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs index 90abdf78bba..4c40976b9b0 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs @@ -60,6 +60,13 @@ public int MaximumFollowRelLink set { base._maximumFollowRelLink = value; } } + /// + /// Gets or sets the ResponseHeadersVariable property. + /// + [Parameter] + [Alias("HV")] + public string ResponseHeadersVariable { get; set; } + #endregion Parameters #region Helper Methods diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeRestMethodCommand.CoreClr.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeRestMethodCommand.CoreClr.cs index 23c9c0a44f7..fbe452d6d0a 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeRestMethodCommand.CoreClr.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/InvokeRestMethodCommand.CoreClr.cs @@ -95,6 +95,12 @@ internal override void ProcessResponse(HttpResponseMessage response) { StreamHelper.SaveStreamToFile(responseStream, QualifiedOutFile, this); } + + if (!String.IsNullOrEmpty(ResponseHeadersVariable)) + { + PSVariableIntrinsics vi = SessionState.PSVariable; + vi.Set(ResponseHeadersVariable, WebResponseHelper.GetHeadersDictionary(response)); + } } } From bb81e3d757a34586fe1fc3f1fb0a0056ffffa5bb Mon Sep 17 00:00:00 2001 From: markekraus Date: Thu, 21 Sep 2017 04:41:39 -0500 Subject: [PATCH 2/7] Add Tests for -ResponseHeadersVariable --- .../WebCmdlets.Tests.ps1 | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index 8851bc8657f..e8d4907265c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -2071,6 +2071,35 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { #endregion charset encoding tests + Context 'Invoke-RestMethod ResponseHeadersVariable Tests' { + It "Verifies Invoke-RestMethod supports -ResponseHeadersVariable" { + $uri = Get-WebListenerUrl -Test '/' + $response = Invoke-RestMethod -Uri $uri -ResponseHeadersVariable 'headers' + + $headers | Should Not BeNullOrEmpty + $headers.'Content-Type' | Should Be 'text/html; charset=utf-8' + $headers.Server | Should Be 'Kestrel' + } + It "Verifies Invoke-RestMethod supports -HV alias" { + $uri = Get-WebListenerUrl -Test '/' + $response = Invoke-RestMethod -Uri $uri -HV 'headers' + + $headers | Should Not BeNullOrEmpty + $headers.'Content-Type' | Should Be 'text/html; charset=utf-8' + $headers.Server | Should Be 'Kestrel' + } + It "Verifies Invoke-RestMethod supports -ResponseHeadersVariable overwriting existing variable" { + $uri = Get-WebListenerUrl -Test '/' + $headers = 'prexisting' + $response = Invoke-RestMethod -Uri $uri -ResponseHeadersVariable 'headers' + + $headers | Should Not Be 'prexisting' + $headers | Should Not BeNullOrEmpty + $headers.'Content-Type' | Should Be 'text/html; charset=utf-8' + $headers.Server | Should Be 'Kestrel' + } + } + BeforeEach { if ($env:http_proxy) { $savedHttpProxy = $env:http_proxy From a718058e6a5866206ed1e3b36f51d645ecbf8fd9 Mon Sep 17 00:00:00 2001 From: markekraus Date: Thu, 21 Sep 2017 04:56:37 -0500 Subject: [PATCH 3/7] [Feature] Run Feature Tests From 2e5c81fc2186d638b7dd15d1431546e195300f11 Mon Sep 17 00:00:00 2001 From: Mark Kraus Date: Thu, 21 Sep 2017 09:02:58 -0500 Subject: [PATCH 4/7] Remove test to address PR feedback --- .../Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index e8d4907265c..e64430ad320 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -2080,14 +2080,7 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $headers.'Content-Type' | Should Be 'text/html; charset=utf-8' $headers.Server | Should Be 'Kestrel' } - It "Verifies Invoke-RestMethod supports -HV alias" { - $uri = Get-WebListenerUrl -Test '/' - $response = Invoke-RestMethod -Uri $uri -HV 'headers' - - $headers | Should Not BeNullOrEmpty - $headers.'Content-Type' | Should Be 'text/html; charset=utf-8' - $headers.Server | Should Be 'Kestrel' - } + It "Verifies Invoke-RestMethod supports -ResponseHeadersVariable overwriting existing variable" { $uri = Get-WebListenerUrl -Test '/' $headers = 'prexisting' From 0073964bd273a9ace7957dc9e27c7a388451469b Mon Sep 17 00:00:00 2001 From: markekraus Date: Fri, 22 Sep 2017 13:39:08 -0500 Subject: [PATCH 5/7] Alais HV -> RHV per request --- .../utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs index 4c40976b9b0..e9a73b46970 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs @@ -64,7 +64,7 @@ public int MaximumFollowRelLink /// Gets or sets the ResponseHeadersVariable property. /// [Parameter] - [Alias("HV")] + [Alias("RHV")] public string ResponseHeadersVariable { get; set; } #endregion Parameters From d4b5305425ead76665d1cde58bdb0e4d02398f34 Mon Sep 17 00:00:00 2001 From: markekraus Date: Fri, 22 Sep 2017 16:55:23 -0500 Subject: [PATCH 6/7] [Feature] Rerun CI From 8971595c7f3788f70caf1dff13948e03fb7b3563 Mon Sep 17 00:00:00 2001 From: markekraus Date: Sat, 23 Sep 2017 05:21:13 -0500 Subject: [PATCH 7/7] [Feature] Remove Superfluous Assertion --- .../Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 index e64430ad320..206cf637bc8 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 @@ -2076,7 +2076,6 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $uri = Get-WebListenerUrl -Test '/' $response = Invoke-RestMethod -Uri $uri -ResponseHeadersVariable 'headers' - $headers | Should Not BeNullOrEmpty $headers.'Content-Type' | Should Be 'text/html; charset=utf-8' $headers.Server | Should Be 'Kestrel' } @@ -2087,7 +2086,6 @@ Describe "Invoke-RestMethod tests" -Tags "Feature" { $response = Invoke-RestMethod -Uri $uri -ResponseHeadersVariable 'headers' $headers | Should Not Be 'prexisting' - $headers | Should Not BeNullOrEmpty $headers.'Content-Type' | Should Be 'text/html; charset=utf-8' $headers.Server | Should Be 'Kestrel' }