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
|
|
|
|
|
{
|
2023-10-12 12:20:15 +00:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
public IEnumerable<string> SupportedContentTypes => new[]
|
2023-01-24 20:48:05 +00:00
|
|
|
{
|
|
|
|
|
MediaTypeNames.Text.Plain,
|
|
|
|
|
MediaTypeNames.Text.RichText,
|
|
|
|
|
MediaTypeNames.Text.Html,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public HttpContent CreateHttpContent(object content, string contentType)
|
|
|
|
|
{
|
2023-03-09 10:24:00 +00:00
|
|
|
var text = content as string ?? content.ToString();
|
2023-01-31 11:40:29 +00:00
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(contentType))
|
|
|
|
|
contentType = MediaTypeNames.Text.Plain;
|
|
|
|
|
|
2023-03-09 10:24:00 +00:00
|
|
|
return new StringContent(text!, Encoding.UTF8, contentType);
|
2023-01-24 20:48:05 +00:00
|
|
|
}
|
|
|
|
|
}
|