Skip to content

Commit 618398e

Browse files
Save & restore the state of [Net.ServicePointManager]::SecurityProtocol (#240)
[Net.ServicePointManager]::SecurityProtocol is a global configuration that was being modified during the execution of `Invoke-GHRestMethod`. With this change, the global state will be cached before the change and restored immediately afterwards. Fixes #230
1 parent 17f6122 commit 618398e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

GitHubCore.ps1

+5
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ function Invoke-GHRestMethod
201201
}
202202

203203
$NoStatus = Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus
204+
$originalSecurityProtocol = [Net.ServicePointManager]::SecurityProtocol
204205

205206
try
206207
{
@@ -560,6 +561,10 @@ function Invoke-GHRestMethod
560561
Set-TelemetryException -Exception $ex -ErrorBucket $errorBucket -Properties $localTelemetryProperties -NoStatus:$NoStatus
561562
throw $newLineOutput
562563
}
564+
finally
565+
{
566+
[Net.ServicePointManager]::SecurityProtocol = $originalSecurityProtocol
567+
}
563568
}
564569

565570
function Invoke-GHRestMethodMultipleResult

0 commit comments

Comments
 (0)