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

Code before:
                    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
                        .ReadAsStringAsync(_cancelToken.Token)
                        .GetAwaiter().GetResult(),
                        MultipartFormDataContent multipartContent => "=> Multipart Form Content"
                        + Environment.NewLine
                        + multipartContent.ReadAsStringAsync(_cancelToken.Token)
                        .GetAwaiter().GetResult(),
                        ByteArrayContent byteContent => InFile is not null
                        ? "[Binary content: "
                        + GetFriendlyContentLength(byteContent.Headers.ContentLength)
                        + "]"
                    : byteContent.ReadAsStringAsync(_cancelToken.Token).GetAwaiter().GetResult(),
                    StreamContent streamContent => "[Stream content: " + GetFriendlyContentLength(streamContent.Headers.ContentLength) + "]",
                    _ => "[Unknown content type]",
                });
                }

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

        private void WriteWebResponseVerboseInfo(HttpResponseMessage response)
        {
            try
            {
                StringBuilder verboseBuilder = new();
                verboseBuilder.Append($"WebResponse: {(int)response.StatusCode} {response.ReasonPhrase ?? response.StatusCode.ToString()}");

                string responseContentType = GetContentType(response);
                if (responseContentType is not null)
                {
                    verboseBuilder.Append($" with {responseContentType} payload");
                }

                long? responseContentLength = response.Content?.Headers?.ContentLength;
                if (responseContentLength is not null)
                {

Review comment (suggestion):
More readable:
```suggestion
                if (request.Headers is not null )
                {
                    allHeaders.AddRange(request.Headers);
                }

                if (request.Content?.Headers is not null )
                {
                    allHeaders.AddRange(request.Content.Headers);
                }

```

Code after:
        {
            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);

                if (!string.IsNullOrEmpty(request.RequestUri?.Query))
                {
                    debugBuilder.Append(DebugHeaderPrefix).AppendLine("QUERY");
                    string[] queryParams = request.RequestUri.Query.TrimStart('?').Split('&');
                    debugBuilder
                        .AppendJoin(Environment.NewLine, queryParams)
                        .AppendLine()
                        .AppendLine();
                }

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

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

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

                if (request.Content is not null)
                {
                    debugBuilder
                    .Append(DebugHeaderPrefix).AppendLine("BODY")
                    .AppendLine(request.Content switch
                    {
                        StringContent stringContent => stringContent
                            .ReadAsStringAsync(_cancelToken.Token)
                            .GetAwaiter().GetResult(),
                        MultipartFormDataContent multipartContent => "=> Multipart Form Content"
                            + Environment.NewLine
                            + multipartContent.ReadAsStringAsync(_cancelToken.Token)
                            .GetAwaiter().GetResult(),
                        ByteArrayContent byteContent => InFile is not null
                            ? "[Binary content: "
                                + ContentHelper.GetFriendlyContentLength(byteContent.Headers.ContentLength)
                                + "]"
                            : byteContent.ReadAsStringAsync(_cancelToken.Token).GetAwaiter().GetResult(),