using Newtonsoft.Json;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HuanMeng.DotNetCore.Utility;

/// <summary>
/// 
/// </summary>
public static class HttpRequestMessageExtensions
{
    public static async Task<string> ToJsonAsync(this HttpRequestMessage request)
    {
        var requestInfo = new
        {
            Method = request.Method.Method,
            Url = request.RequestUri?.ToString(),
            Headers = request.Headers,
            Content = request.Content != null ? await request.Content.ReadAsStringAsync() : null
        };

        return JsonConvert.SerializeObject(requestInfo, Formatting.None);
    }
}
