2022-10-25 13:52:55 +00:00
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using Elsa.Http.Constants;
|
|
|
|
|
|
|
|
|
|
namespace Elsa.Http.ContentWriters;
|
|
|
|
|
|
2023-01-16 18:42:45 +00:00
|
|
|
public class StringHttpContentWriter : IHttpContentWriter
|
2022-10-25 13:52:55 +00:00
|
|
|
{
|
|
|
|
|
private List<string> SupportedContentTypes = new() {MimeTypes.ApplicationJson, MimeTypes.ApplicationXml};
|
|
|
|
|
|
|
|
|
|
public bool SupportsContentType(string contentType)
|
|
|
|
|
{
|
|
|
|
|
return SupportedContentTypes.Contains(contentType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public HttpContent GetContent<T>(T content, string? contentType = null)
|
|
|
|
|
{
|
|
|
|
|
var serializedContent = JsonSerializer.Serialize(content);
|
|
|
|
|
return new StringContent(serializedContent, Encoding. UTF8, contentType);
|
|
|
|
|
}
|
|
|
|
|
}
|