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

Code before:
                })
                {
                    if (headerSource is not null)
                    {
                        allHeaders.AddRange(headerSource);
                    }
                }

                foreach (var header in allHeaders.OrderBy(h => h.Key))
                {
                    debugBuilder.AppendLine($"{header.Key}: {string.Join(", ", header.Value)}");
                }

                if (response.Content is not null)
                {
                    debugBuilder.AppendLine(DebugHeaderPrefix + "BODY");

                    if (IsTextBasedContentType(GetContentType(response)))
                    {
                        debugBuilder.AppendLine(
                        response.Content.ReadAsStringAsync(_cancelToken.Token)
                        .GetAwaiter().GetResult());
                    }
                    else
                    {
                        debugBuilder.AppendLine($"[Binary content: {GetFriendlyContentLength(response.Content?.Headers?.ContentLength)}]");
                    }
                }

                WriteDebug(debugBuilder.ToString().Trim());
            }
            catch (Exception ex)
            {
                // Just in case there are any edge cases we missed, we don't break workflows with an exception
                WriteVerbose($"Failed to Write WebResponse Debug Info: {ex} {ex.StackTrace}");
            }
        }

        internal virtual void UpdateSession(HttpResponseMessage response)
        {
            ArgumentNullException.ThrowIfNull(response);
        }

        #endregion Virtual Methods

        #region Helper Methods

        internal static TimeSpan ConvertTimeoutSecondsToTimeSpan(int timeout) => timeout > 0 ? TimeSpan.FromSeconds(timeout) : Timeout.InfiniteTimeSpan;

        private Uri PrepareUri(Uri uri)
        {

Review comment (bug):
```suggestion
                        debugBuilder.AppendLine(
                            response.Content.ReadAsStringAsync(_cancelToken.Token).GetAwaiter().GetResult());
```

Code after:
                if (responseContentType is not null)
                {
                    verboseBuilder.Append($" with {responseContentType} payload");
                }

                long? responseContentLength = response.Content?.Headers?.ContentLength;
                if (responseContentLength is not null)
                {
                    verboseBuilder.Append($" with body size {ContentHelper.GetFriendlyContentLength(responseContentLength)}");
                }

                WriteVerbose(verboseBuilder.ToString().Trim());
            }
            catch (Exception ex)
            {
                // Just in case there are any edge cases we missed, we don't break workflows with an exception
                WriteVerbose($"Failed to Write WebResponse Verbose Info: {ex} {ex.StackTrace}");
            }
        }

        private void WriteWebResponseDebugInfo(HttpResponseMessage response)
        {
            try
            {
                // Typical basic example
                // WebResponse Detail
                // --- HEADERS
                // Date: Fri, 09 May 2025 18:06:44 GMT
                // Server: Kestrel
                // Set-Cookie: ARRAffinity=ee0b467f95b53d8dcfe48aeeb4173f93cf819be6e4721f434341647f4695039d;Path=/;HttpOnly;Secure;Domain=httpstat.us, ARRAffinitySameSite=ee0b467f95b53d8dcfe48aeeb4173f93cf819be6e4721f434341647f4695039d;Path=/;HttpOnly;SameSite=None;Secure;Domain=httpstat.us
                // Strict-Transport-Security: max-age=2592000
                // Request-Context: appId=cid-v1:3548b0f5-7f75-492f-82bb-b6eb0e864e53
                // Content-Length: 6
                // Content-Type: text/plain
                // --- BODY
                // 200 OK
                StringBuilder debugBuilder = new("WebResponse Detail" + Environment.NewLine, 512);

                debugBuilder.Append(DebugHeaderPrefix).AppendLine("HEADERS");

                foreach (var headerSet in new HttpHeaders?[] { response.Headers, response.Content?.Headers })
                {
                    if (headerSet is null)
                    {
                        continue;
                    }

                    debugBuilder.AppendLine(headerSet.ToString());
                }

                if (response.Content is not null)