Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,7 @@ public abstract partial class WebRequestPSCmdlet : PSCmdlet
/// </summary>
[Parameter]
[ValidateRange(0, int.MaxValue)]
public virtual int MaximumRedirection
{
get { return _maximumRedirection; }

set { _maximumRedirection = value; }
}

private int _maximumRedirection = -1;
public virtual int MaximumRedirection { get; set; } = -1;

/// <summary>
/// Gets or sets the MaximumRetryCount property, which determines the number of retries of a failed web request.
Expand Down Expand Up @@ -664,11 +657,6 @@ internal virtual void PrepareSession()
WebSession.Proxy = webProxy;
}

if (MaximumRedirection > -1)
{
WebSession.MaximumRedirection = MaximumRedirection;
}

// store the other supplied headers
if (Headers != null)
{
Expand All @@ -686,13 +674,9 @@ internal virtual void PrepareSession()
}
}

if (MaximumRetryCount > 0)
{
WebSession.MaximumRetryCount = MaximumRetryCount;

// only set retry interval if retry count is set.
WebSession.RetryIntervalInSeconds = RetryIntervalSec;
}
// will be removed after merging #18717
// only set retry interval if retry count is set.
WebSession.RetryIntervalInSeconds = RetryIntervalSec;
}

#endregion Virtual Methods
Expand Down Expand Up @@ -1032,15 +1016,15 @@ internal virtual HttpClient GetHttpClient(bool handleRedirect)
{
handler.AllowAutoRedirect = false;
}
else if (WebSession.MaximumRedirection > -1)
else if (MaximumRedirection > -1)
{
if (WebSession.MaximumRedirection == 0)
if (MaximumRedirection == 0)
{
handler.AllowAutoRedirect = false;
}
else
{
handler.MaxAutomaticRedirections = WebSession.MaximumRedirection;
handler.MaxAutomaticRedirections = MaximumRedirection;
}
}

Expand Down Expand Up @@ -1346,7 +1330,7 @@ private bool ShouldRetry(HttpStatusCode code)
int intCode = (int)code;
return
(
(intCode == 304 || (intCode >= 400 && intCode <= 599)) && WebSession.MaximumRetryCount > 0
(intCode == 304 || (intCode >= 400 && intCode <= 599)) && MaximumRetryCount > 0
);
}

Expand All @@ -1357,7 +1341,7 @@ internal virtual HttpResponseMessage GetResponse(HttpClient client, HttpRequestM
if (request == null) { throw new ArgumentNullException(nameof(request)); }

// Add 1 to account for the first request.
int totalRequests = WebSession.MaximumRetryCount + 1;
int totalRequests = MaximumRetryCount + 1;
HttpRequestMessage req = request;
HttpResponseMessage response = null;

Expand All @@ -1375,9 +1359,9 @@ internal virtual HttpResponseMessage GetResponse(HttpClient client, HttpRequestM
_cancelToken = null;

// if explicit count was provided, reduce it for this redirection.
if (WebSession.MaximumRedirection > 0)
if (MaximumRedirection > 0)
{
WebSession.MaximumRedirection--;
MaximumRedirection--;
}
// For selected redirects that used POST, GET must be used with the
// redirected Location.
Expand Down Expand Up @@ -1593,7 +1577,7 @@ protected override void ProcessRecord()
// Errors with redirection counts of greater than 0 are handled automatically by .NET, but are
// impossible to detect programmatically when we hit this limit. By handling this ourselves
// (and still writing out the result), users can debug actual HTTP redirect problems.
if (WebSession.MaximumRedirection == 0 && IsRedirectCode(response.StatusCode)) // Indicate "HttpClientHandler.AllowAutoRedirect == false"
if (MaximumRedirection == 0 && IsRedirectCode(response.StatusCode)) // Indicate "HttpClientHandler.AllowAutoRedirect == false"
{
ErrorRecord er = new(new InvalidOperationException(), "MaximumRedirectExceeded", ErrorCategory.InvalidOperation, request);
er.ErrorDetails = new ErrorDetails(WebCmdletStrings.MaximumRedirectionCountExceeded);
Expand Down