diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs index ad640dcfd4..b9345ff260 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/StreamHelper.cs @@ -298,6 +298,7 @@ namespace Microsoft.PowerShell.Commands Task copyTask = input.CopyToAsync(output, cancellationToken); + bool wroteProgress = false; ProgressRecord record = new( ActivityId, WebCmdletStrings.WriteRequestProgressActivity, @@ -313,23 +314,32 @@ namespace Microsoft.PowerShell.Commands Utils.DisplayHumanReadableFileSize(output.Position), totalDownloadSize); - if (contentLength != null && contentLength > 0) + if (contentLength > 0) { record.PercentComplete = Math.Min((int)(output.Position * 100 / (long)contentLength), 100); } cmdlet.WriteProgress(record); - } - - if (copyTask.IsCompleted) - { - record.StatusDescription = StringUtil.Format(WebCmdletStrings.WriteRequestComplete, output.Position); - cmdlet.WriteProgress(record); + wroteProgress = true; } } catch (OperationCanceledException) { } + finally + { + if (wroteProgress) + { + // Write out the completion progress record only if we did render the progress. + record.StatusDescription = StringUtil.Format( + copyTask.IsCompleted + ? WebCmdletStrings.WriteRequestComplete + : WebCmdletStrings.WriteRequestCancelled, + output.Position); + record.RecordType = ProgressRecordType.Completed; + cmdlet.WriteProgress(record); + } + } } /// diff --git a/src/Microsoft.PowerShell.Commands.Utility/resources/WebCmdletStrings.resx b/src/Microsoft.PowerShell.Commands.Utility/resources/WebCmdletStrings.resx index f0ec8a4b02..e4f34c17ea 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/resources/WebCmdletStrings.resx +++ b/src/Microsoft.PowerShell.Commands.Utility/resources/WebCmdletStrings.resx @@ -199,7 +199,7 @@ The cmdlet cannot run because the following parameter is missing: Proxy. Provide a valid proxy URI for the Proxy parameter when using the ProxyCredential or ProxyUseDefaultCredentials parameters, then retry. - Reading web response stream completed. Downloaded: {0} + Reading web response stream completed. Bytes downloaded: {0} Reading web response stream @@ -219,6 +219,9 @@ Web request completed. (Number of bytes processed: {0}) + + Web request cancelled. (Number of bytes processed: {0}) + Web request status