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 @@ -198,6 +198,12 @@ public abstract partial class WebRequestPSCmdlet : PSCmdlet
[Parameter]
public virtual SecureString Token { get; set; }

/// <summary>
/// Gets or sets the AllowInsecureRedirect property used to follow HTTP redirects from HTTPS.
/// </summary>
[Parameter]
public virtual SwitchParameter AllowInsecureRedirect { get; set; }

#endregion

#region Headers
Expand Down Expand Up @@ -968,7 +974,7 @@ internal virtual HttpClient GetHttpClient(bool handleRedirect)
}

// This indicates GetResponse will handle redirects.
if (handleRedirect)
if (handleRedirect || AllowInsecureRedirect)
{
handler.AllowAutoRedirect = false;
}
Expand Down Expand Up @@ -1313,7 +1319,7 @@ internal virtual HttpResponseMessage GetResponse(HttpClient client, HttpRequestM
_cancelToken = new CancellationTokenSource();
response = client.SendAsync(req, HttpCompletionOption.ResponseHeadersRead, _cancelToken.Token).GetAwaiter().GetResult();

if (keepAuthorization && IsRedirectCode(response.StatusCode) && response.Headers.Location is not null)
if ((keepAuthorization || (AllowInsecureRedirect && (WebSession.MaximumRedirection > 0 || WebSession.MaximumRedirection == -1))) && IsRedirectCode(response.StatusCode) && response.Headers.Location != null)
{
_cancelToken.Cancel();
_cancelToken = null;
Expand Down