[fix]Config创建默认配置文件的开关Runtime.CreateConfigOnMissing,仅需对自动创建生效,而不应该阻止用户主动Save
智能大石头 编写于 2024-08-09 00:30:41 石头 提交于 2024-08-10 14:22:24
X
using System.Net.Http;
using NewLife.Data;

namespace NewLife.Http.Headers;

public class HttpRequestMessage : HttpRequest
{
    public HttpContent Content { get; set; }

    //public HttpRequestHeaders Headers { get; set; }

    public HttpRequestMessage() { }

    public HttpRequestMessage(HttpMethod method, Uri requestUri)
    {
        Method = method + "";
        RequestUri = requestUri;
    }

    public HttpRequestMessage(HttpMethod method, String requestUri)
    {
        Method = method + "";
        RequestUri = new Uri(requestUri, UriKind.RelativeOrAbsolute);
    }

    /// <summary>序列化请求前,把Content内容放到头部</summary>
    /// <returns></returns>
    public override Packet Build()
    {
        var content = Content;
        if (content != null)
        {
            if (Body == null)
            {
                if (content is ByteArrayContent btc)
                    Body = btc.Data;
                else
                    Body = content.ReadAsByteArrayAsync().Result;
            }
            if (ContentType.IsNullOrEmpty() && content.Headers != null && !content.Headers.ContentType.IsNullOrEmpty())
            {
                ContentType = content.Headers.ContentType;
            }
        }

        return base.Build();
    }
}