elsa-core/src/modules/Elsa.Http/ContentWriters/TextContentFactory.cs
Sipke Schoorstra c63369b567 Add system namespaces
For some reason my tooling no longer sees the global usings.
2023-10-20 09:50:57 +02:00

31 lines
893 B
C#

using System.Collections.Generic;
using System.Net.Http;
using System.Net.Mime;
using System.Text;
namespace Elsa.Http.ContentWriters;
/// <summary>
/// Creates a <see cref="StringContent"/> object for text/plain, text/richtext and text/html content types.
/// </summary>
public class TextContentFactory : IHttpContentFactory
{
/// <inheritdoc />
public IEnumerable<string> SupportedContentTypes => new[]
{
MediaTypeNames.Text.Plain,
MediaTypeNames.Text.RichText,
MediaTypeNames.Text.Html,
};
/// <inheritdoc />
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);
}
}