mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Small changes in Webcmdlets (#19109)
This commit is contained in:
+15
-23
@@ -605,7 +605,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (CertificateThumbprint is not null)
|
||||
{
|
||||
X509Store store = new(StoreName.My, StoreLocation.CurrentUser);
|
||||
using X509Store store = new(StoreName.My, StoreLocation.CurrentUser);
|
||||
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
|
||||
X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
|
||||
X509Certificate2Collection tbCollection = (X509Certificate2Collection)collection.Find(X509FindType.FindByThumbprint, CertificateThumbprint, false);
|
||||
@@ -1230,7 +1230,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
internal virtual HttpResponseMessage GetResponse(HttpClient client, HttpRequestMessage request, bool handleRedirect)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(client);
|
||||
|
||||
ArgumentNullException.ThrowIfNull(request);
|
||||
|
||||
// Add 1 to account for the first request.
|
||||
@@ -1241,7 +1240,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
do
|
||||
{
|
||||
// Track the current URI being used by various requests and re-requests.
|
||||
var currentUri = req.RequestUri;
|
||||
Uri currentUri = req.RequestUri;
|
||||
|
||||
_cancelToken = new CancellationTokenSource();
|
||||
response = client.SendAsync(req, HttpCompletionOption.ResponseHeadersRead, _cancelToken.Token).GetAwaiter().GetResult();
|
||||
@@ -1259,6 +1258,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
WebSession.MaximumRedirection--;
|
||||
}
|
||||
|
||||
// For selected redirects that used POST, GET must be used with the
|
||||
// redirected Location.
|
||||
// Since GET is the default; POST only occurs when -Method POST is used.
|
||||
@@ -1269,12 +1269,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
currentUri = new Uri(request.RequestUri, response.Headers.Location);
|
||||
|
||||
// Continue to handle redirection
|
||||
using (client = GetHttpClient(handleRedirect))
|
||||
using (HttpRequestMessage redirectRequest = GetRequest(currentUri))
|
||||
{
|
||||
response = GetResponse(client, redirectRequest, handleRedirect);
|
||||
}
|
||||
using HttpRequestMessage redirectRequest = GetRequest(currentUri);
|
||||
response = GetResponse(client, redirectRequest, handleRedirect);
|
||||
}
|
||||
|
||||
// Request again without the Range header because the server indicated the range was not satisfiable.
|
||||
@@ -1296,11 +1294,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
using (HttpRequestMessage requestWithoutRange = GetRequest(currentUri))
|
||||
{
|
||||
FillRequestStream(requestWithoutRange);
|
||||
long requestContentLength = 0;
|
||||
if (requestWithoutRange.Content is not null)
|
||||
{
|
||||
requestContentLength = requestWithoutRange.Content.Headers.ContentLength.Value;
|
||||
}
|
||||
|
||||
long requestContentLength = requestWithoutRange.Content is null ? 0 : requestWithoutRange.Content.Headers.ContentLength.Value;
|
||||
|
||||
string reqVerboseMsg = string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
@@ -1413,11 +1408,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
FillRequestStream(request);
|
||||
try
|
||||
{
|
||||
long requestContentLength = 0;
|
||||
if (request.Content is not null)
|
||||
{
|
||||
requestContentLength = request.Content.Headers.ContentLength.Value;
|
||||
}
|
||||
long requestContentLength = request.Content is null ? 0 : request.Content.Headers.ContentLength.Value;
|
||||
|
||||
string reqVerboseMsg = string.Format(
|
||||
CultureInfo.CurrentCulture,
|
||||
@@ -1472,13 +1463,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
StreamReader reader = null;
|
||||
try
|
||||
{
|
||||
reader = new StreamReader(StreamHelper.GetResponseStream(response));
|
||||
// remove HTML tags making it easier to read
|
||||
reader = new(StreamHelper.GetResponseStream(response));
|
||||
|
||||
// Remove HTML tags making it easier to read
|
||||
detailMsg = System.Text.RegularExpressions.Regex.Replace(reader.ReadToEnd(), "<[^>]*>", string.Empty);
|
||||
}
|
||||
catch (Exception)
|
||||
catch
|
||||
{
|
||||
// catch all
|
||||
// Catch all
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -1551,7 +1543,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementing ^C, after start the BeginGetResponse.
|
||||
/// To implement ^C.
|
||||
/// </summary>
|
||||
protected override void StopProcessing() => _cancelToken?.Cancel();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user