Repository: PowerShell/PowerShell
File: src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/InvokeRestMethodCommand.Common.cs (C#)

Code before:

        /// <summary>
        /// Gets or sets the variable name to use for storing the status code from the response.
        /// </summary>
        [Parameter]
        public string? StatusCodeVariable { get; set; }

        #endregion Parameters

        #region Virtual Method Overrides

        /// <summary>
        /// Process the web response and output corresponding objects.
        /// </summary>
        /// <param name="response"></param>
        internal override void ProcessResponse(HttpResponseMessage response)
        {
            ArgumentNullException.ThrowIfNull(response);
            ArgumentNullException.ThrowIfNull(_cancelToken);

            Stream baseResponseStream = StreamHelper.GetResponseStream(response, _cancelToken.Token);

            if (ShouldWriteToPipeline)
            {
                using BufferingStreamReader responseStream = new(baseResponseStream, _cancelToken.Token);

                // First see if it is an RSS / ATOM feed, in which case we can
                // stream it - unless the user has overridden it with a return type of "XML"
                if (TryProcessFeedStream(responseStream))
                {
                    // Do nothing, content has been processed.
                }
                else
                {
                    // Try to get the response encoding from the ContentType header.
                    string? characterSet = WebResponseHelper.GetCharacterSet(response);

                    string str = StreamHelper.DecodeStream(responseStream, characterSet, out Encoding encoding, _cancelToken.Token);

                    string encodingVerboseName;
                    try
                    {
                        encodingVerboseName = encoding.HeaderName;
                    }
                    catch
                    {
                        encodingVerboseName = string.Empty;
                    }

                    // NOTE: Tests use this verbose output to verify the encoding.
                    WriteVerbose(string.Create(System.Globalization.CultureInfo.InvariantCulture, $"Content encoding: {encodingVerboseName}"));

Review comment (suggestion):
```suggestion
                using BufferingStreamReader responseStream = new(baseResponseStream, perReadTimeout, _cancelToken.Token);
```

Code after:

        /// <summary>
        /// Gets or sets the variable name to use for storing the status code from the response.
        /// </summary>
        [Parameter]
        public string? StatusCodeVariable { get; set; }

        #endregion Parameters

        #region Virtual Method Overrides

        /// <summary>
        /// Process the web response and output corresponding objects.
        /// </summary>
        /// <param name="response"></param>
        internal override void ProcessResponse(HttpResponseMessage response)
        {
            ArgumentNullException.ThrowIfNull(response);
            ArgumentNullException.ThrowIfNull(_cancelToken);

            TimeSpan perReadTimeout = ConvertTimeoutSecondsToTimeSpan(OperationTimeoutSeconds);
            Stream baseResponseStream = StreamHelper.GetResponseStream(response, _cancelToken.Token);

            if (ShouldWriteToPipeline)
            {
                using BufferingStreamReader responseStream = new(baseResponseStream, perReadTimeout, _cancelToken.Token);

                // First see if it is an RSS / ATOM feed, in which case we can
                // stream it - unless the user has overridden it with a return type of "XML"
                if (TryProcessFeedStream(responseStream))
                {
                    // Do nothing, content has been processed.
                }
                else
                {
                    // Try to get the response encoding from the ContentType header.
                    string? characterSet = WebResponseHelper.GetCharacterSet(response);
                    string str = StreamHelper.DecodeStream(responseStream, characterSet, out Encoding encoding, perReadTimeout, _cancelToken.Token);

                    string encodingVerboseName;
                    try
                    {
                        encodingVerboseName = encoding.HeaderName;
                    }
                    catch
                    {
                        encodingVerboseName = string.Empty;
                    }

                    // NOTE: Tests use this verbose output to verify the encoding.
                    WriteVerbose(string.Create(System.Globalization.CultureInfo.InvariantCulture, $"Content encoding: {encodingVerboseName}"));