Update SendHttpRequest to determine type based on content type

By default, the associated variable type will be used. But when no variable is associated, we should fallback to content type checking.
This commit is contained in:
Sipke Schoorstra 2023-07-13 16:16:53 +02:00
parent 3a7b3af3b0
commit 78f01f267b

View file

@ -1,5 +1,6 @@
using System.Net.Http.Headers;
using System.Text.Json.Serialization;
using System.Xml.Linq;
using Elsa.Extensions;
using Elsa.Http.ContentWriters;
using Elsa.Workflows.Core;
@ -7,6 +8,7 @@ using Elsa.Workflows.Core.Attributes;
using Elsa.Workflows.Core.Contracts;
using Elsa.Workflows.Core.Models;
using JetBrains.Annotations;
using Newtonsoft.Json.Linq;
using HttpRequestHeaders = Elsa.Http.Models.HttpRequestHeaders;
namespace Elsa.Http;
@ -211,6 +213,12 @@ public abstract class SendHttpRequestBase : Activity<HttpResponseMessage>
var contentStream = await httpContent.ReadAsStreamAsync(cancellationToken);
var contentType = httpContent.Headers.ContentType?.MediaType!;
targetType ??= contentType switch
{
"application/json" => typeof(object),
_ => typeof(string)
};
return await context.ParseContentAsync(contentStream, contentType, targetType, cancellationToken);
}