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

Code before:
            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.AppendLine(DebugHeaderPrefix + "HEADERS");

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

                    foreach (var header in headerSet)
                    {
                        debugBuilder.AppendLine($"{header.Key}: {string.Join(", ", header.Value)}");
                    }
                }

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

                    if (ContentHelper.IsTextBasedContentType(ContentHelper.GetContentType(response)))
                    {
                        debugBuilder.AppendLine(
                            response.Content.ReadAsStringAsync(_cancelToken.Token)
                            .GetAwaiter().GetResult());
                    }
                    else

Review comment (bug):
```suggestion
                debugBuilder.Append(DebugHeaderPrefix).AppendLine("HEADERS");
```

Code after:
                // 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)
                {
                    debugBuilder.Append(DebugHeaderPrefix).AppendLine("BODY");

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