using System.Diagnostics.CodeAnalysis; using System.Text; namespace Uwaa.HTTP; /// /// Content served as the body of a HTTP request or response. /// public struct HttpContent { public static implicit operator HttpContent?([NotNullWhen(false)] string? value) { return value == null ? null : new HttpContent("text/plain", value); } /// /// The MIME type of the HTTP content. /// public MIMEType Type; /// /// The raw HTTP content body, as bytes. /// public byte[] Content; /// /// Converts the contents to a UTF-8 string. /// public string AsText => Encoding.UTF8.GetString(Content); public HttpContent(MIMEType type, string body) { Type = type; Content = Encoding.UTF8.GetBytes(body); } public HttpContent(MIMEType type, byte[] body) { Type = type; Content = body; } public override string ToString() => Type.ToString(); }