using System.Net.Mime; using System.Text; namespace Elsa.Http.ContentWriters; /// /// Creates a object for text/plain, text/richtext and text/html content types. /// public class TextContentFactory : IHttpContentFactory { private readonly List _supportedContentTypes = new() { MediaTypeNames.Text.Plain, MediaTypeNames.Text.RichText, MediaTypeNames.Text.Html, }; /// public bool SupportsContentType(string contentType) => _supportedContentTypes.Contains(contentType); /// public HttpContent CreateHttpContent(object content, string contentType) { var text = content as string ?? content.ToString(); if (string.IsNullOrWhiteSpace(contentType)) contentType = MediaTypeNames.Text.Plain; return new StringContent(text!, Encoding.UTF8, contentType); } }