Skip to content
Merged
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 @@ -740,7 +740,7 @@ private Uri PrepareUri(Uri uri)
LanguagePrimitives.TryConvertTo<IDictionary>(Body, out bodyAsDictionary);
if ((bodyAsDictionary != null)
&& ((IsStandardMethodSet() && (Method == WebRequestMethod.Default || Method == WebRequestMethod.Get))
|| (IsCustomMethodSet() && CustomMethod.ToUpperInvariant() == "GET")))
|| (IsCustomMethodSet() && CustomMethod.ToUpperInvariant() == "GET")))
{
UriBuilder uriBuilder = new(uri);
if (uriBuilder.Query != null && uriBuilder.Query.Length > 1)
Expand Down Expand Up @@ -1318,9 +1318,9 @@ private static bool IsRedirectCode(HttpStatusCode code)
int intCode = (int)code;
return
(
(intCode >= 300 && intCode < 304)
||
intCode == 307
(intCode >= 300 && intCode < 304) ||
intCode == 307 ||
intCode == 308
);
}

Expand All @@ -1330,32 +1330,24 @@ private static bool IsRedirectToGet(HttpStatusCode code)
{
return
(
code == HttpStatusCode.Found
||
code == HttpStatusCode.Moved
||
code == HttpStatusCode.Redirect
||
code == HttpStatusCode.RedirectMethod
||
code == HttpStatusCode.SeeOther
||
code == HttpStatusCode.Ambiguous
||
code == HttpStatusCode.Found ||
code == HttpStatusCode.Moved ||
code == HttpStatusCode.Redirect ||
code == HttpStatusCode.RedirectMethod ||
code == HttpStatusCode.SeeOther ||
code == HttpStatusCode.Ambiguous ||
code == HttpStatusCode.MultipleChoices
);
}

// Returns true if the status code shows a server or client error and MaximumRetryCount > 0
private bool ShouldRetry(HttpStatusCode code)
{
int intCode = (int)code;

if (((intCode == 304) || (intCode >= 400 && intCode <= 599)) && WebSession.MaximumRetryCount > 0)
{
return true;
}

return false;
return
(
(intCode == 304 || (intCode >= 400 && intCode <= 599)) && WebSession.MaximumRetryCount > 0
);
}

internal virtual HttpResponseMessage GetResponse(HttpClient client, HttpRequestMessage request, bool keepAuthorization)
Expand Down Expand Up @@ -1601,16 +1593,11 @@ 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) // Indicate "HttpClientHandler.AllowAutoRedirect == false"
if (WebSession.MaximumRedirection == 0 && IsRedirectCode(response.StatusCode)) // Indicate "HttpClientHandler.AllowAutoRedirect == false"
{
if (response.StatusCode == HttpStatusCode.Found ||
response.StatusCode == HttpStatusCode.Moved ||
response.StatusCode == HttpStatusCode.MovedPermanently)
{
ErrorRecord er = new(new InvalidOperationException(), "MaximumRedirectExceeded", ErrorCategory.InvalidOperation, request);
er.ErrorDetails = new ErrorDetails(WebCmdletStrings.MaximumRedirectionCountExceeded);
WriteError(er);
}
ErrorRecord er = new(new InvalidOperationException(), "MaximumRedirectExceeded", ErrorCategory.InvalidOperation, request);
er.ErrorDetails = new ErrorDetails(WebCmdletStrings.MaximumRedirectionCountExceeded);
WriteError(er);
}
}
catch (HttpRequestException ex)
Expand Down