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

Code before:
                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: "
                                + ContentHelper.GetFriendlyContentLength(byteContent.Headers.ContentLength)
                                + "]"
                            : byteContent.ReadAsStringAsync(_cancelToken.Token).GetAwaiter().GetResult(),
                        StreamContent streamContent =>
                            "[Stream content: " + ContentHelper.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
            {
                // We know the message will usually be at least a certain size, so this reduces allocations.
                StringBuilder verboseBuilder = new(128);
                verboseBuilder.Append($"WebResponse: {(int)response.StatusCode} {response.ReasonPhrase ?? response.StatusCode.ToString()}");

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

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

Review comment (bug):
I'd want to see _exact_ length in debug, maybe formatted with thousands chars.
Ex.:
`1 000 001 bytes` vs `1 MB`
Or we could combine `[Binary content: 1 MB (1 000 001 bytes)`

Code after:
                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(),
                        StreamContent streamContent =>
                            "[Stream content: " + ContentHelper.GetFriendlyContentLength(streamContent.Headers.ContentLength) + "]",
                        _ => "[Unknown content type]",
                    })
                    .AppendLine();
                }

                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
            {
                // Typical basic example: WebResponse: 200 OK with text/plain payload body size 6 B (6 bytes)
                StringBuilder verboseBuilder = new(128);
                verboseBuilder.Append($"WebResponse: {(int)response.StatusCode} {response.ReasonPhrase ?? response.StatusCode.ToString()}");