2023-01-24 20:48:05 +00:00
|
|
|
using System.Net.Mime;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Elsa.Http.ContentWriters;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-01-24 21:39:31 +00:00
|
|
|
/// Creates a <see cref="StringContent"/> object for text/plain, text/richtext and text/html content types.
|
2023-01-24 20:48:05 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public class TextContentFactory : IHttpContentFactory
|
|
|
|
|
{
|
|
|
|
|
private readonly List<string> _supportedContentTypes = new()
|
|
|
|
|
{
|
|
|
|
|
MediaTypeNames.Text.Plain,
|
|
|
|
|
MediaTypeNames.Text.RichText,
|
|
|
|
|
MediaTypeNames.Text.Html,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public bool SupportsContentType(string contentType) => _supportedContentTypes.Contains(contentType);
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public HttpContent CreateHttpContent(object content, string contentType)
|
|
|
|
|
{
|
|
|
|
|
var text = content as string ?? "";
|
2023-01-31 11:40:29 +00:00
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(contentType))
|
|
|
|
|
contentType = MediaTypeNames.Text.Plain;
|
|
|
|
|
|
2023-01-24 20:48:05 +00:00
|
|
|
return new StringContent(text, Encoding.UTF8, contentType);
|
|
|
|
|
}
|
|
|
|
|
}
|