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

Code before:
                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 WebRequest Verbose Info: {ex} {ex.StackTrace}");
            }
        }

        private void WriteWebRequestDebugInfo(HttpRequestMessage request)
        {
            try
            {
                StringBuilder debugBuilder = new("WebRequest Detail");

                if (!string.IsNullOrEmpty(request.RequestUri.Query))
                {
                    debugBuilder.AppendLine(DebugHeaderPrefix + "QUERY");
                    string[] queryParams = request.RequestUri.Query.TrimStart('?').Split('&');
                    foreach (string param in queryParams)
                    {
                        debugBuilder.AppendLine(param);
                    }
                }

                debugBuilder.AppendLine(DebugHeaderPrefix + "HEADERS");

                List<KeyValuePair<string, IEnumerable<string>>> allHeaders = new();
                foreach (HttpHeaders headerSource in new HttpHeaders[]
                {
                request.Headers,
                request.Content?.Headers,
                })
                {
                    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 (request.Content is not null)
                {
                    debugBuilder
                    .AppendLine(DebugHeaderPrefix + "BODY")
                    .AppendLine(request.Content switch
                    {
                        StringContent stringContent => stringContent

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

Code after:
        private void WriteWebRequestVerboseInfo(HttpRequestMessage request)
        {
            try
            {
                // Typical Basic Example: 'WebRequest: v1.1 POST https://httpstat.us/200 with query length 6'
                StringBuilder verboseBuilder = new(128);

                // "Redact" the query string from verbose output, the details will be visible in Debug output
                string uriWithoutQuery = request.RequestUri?.GetLeftPart(UriPartial.Path) ?? string.Empty;
                verboseBuilder.Append($"WebRequest: v{request.Version} {request.Method} {uriWithoutQuery}");
                if (request.RequestUri?.Query is not null && request.RequestUri.Query.Length > 1)
                {
                    verboseBuilder.Append($" with query length {request.RequestUri.Query.Length - 1}");
                }

                string? requestContentType = ContentHelper.GetContentType(request);
                if (requestContentType is not null)
                {
                    verboseBuilder.Append($" with {requestContentType} payload");
                }

                long? requestContentLength = request.Content?.Headers?.ContentLength;
                if (requestContentLength is not null)
                {
                    verboseBuilder.Append($" with body size {ContentHelper.GetFriendlyContentLength(requestContentLength)}");
                }
                if (OutFile is not null)
                {
                    verboseBuilder.Append($" output to {QualifyFilePath(OutFile)}");
                }

                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 WebRequest Verbose Info: {ex} {ex.StackTrace}");
            }
        }

        private void WriteWebRequestDebugInfo(HttpRequestMessage request)
        {
            try
            {
                // Typical basic example:
                // WebRequest Detail
                // ---QUERY
                // test = 5
                // --- HEADERS
                // User - Agent: Mozilla / 5.0, (Linux;Ubuntu 24.04.2 LTS;en - US), PowerShell / 7.6.0
                StringBuilder debugBuilder = new("WebRequest Detail" + Environment.NewLine, 512);