add text/html content parser as string content (#5460)
* add text/html content parser as string content * add text/html content parser in configuration --------- Co-authored-by: Jérémie DEVILLARD <jdevillard@users.noreply.github.com>
This commit is contained in:
parent
ad236f626f
commit
a130363a41
|
|
@ -161,7 +161,8 @@ public class HttpFeature : FeatureBase
|
|||
// Content parsers.
|
||||
.AddSingleton<IHttpContentParser, JsonHttpContentParser>()
|
||||
.AddSingleton<IHttpContentParser, XmlHttpContentParser>()
|
||||
.AddSingleton<IHttpContentParser, PlainTextHttpContentParser>()
|
||||
.AddSingleton<IHttpContentParser, PlainTextHttpContentParser>()
|
||||
.AddSingleton<IHttpContentParser, TextHtmlHttpContentParser>()
|
||||
|
||||
// HTTP content factories.
|
||||
.AddScoped<IHttpContentFactory, TextContentFactory>()
|
||||
|
|
|
|||
24
src/modules/Elsa.Http/Parsers/TextHtmlHttpContentParser.cs
Normal file
24
src/modules/Elsa.Http/Parsers/TextHtmlHttpContentParser.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
using Elsa.Http.Contracts;
|
||||
|
||||
namespace Elsa.Http.Parsers;
|
||||
|
||||
/// <summary>
|
||||
/// Reads text/html content type streams.
|
||||
/// </summary>
|
||||
// TODO: found a library to use a Html Content Parser and use a complexe object Type, until this, this class allow to accept request send using text/html content-type
|
||||
public class TextHtmlHttpContentParser : IHttpContentParser
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public int Priority => 0;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool GetSupportsContentType(string contentType) => contentType.Contains("text/html", StringComparison.InvariantCultureIgnoreCase);
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<object> ReadAsync(Stream content, Type? returnType, CancellationToken cancellationToken)
|
||||
{
|
||||
using var reader = new StreamReader(content, leaveOpen: true);
|
||||
var stringContent = await reader.ReadToEndAsync();
|
||||
return stringContent;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue