From 78f01f267b84561e91e32c684e1daf286fe5f504 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Thu, 13 Jul 2023 16:16:53 +0200 Subject: [PATCH] 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. --- src/modules/Elsa.Http/Activities/SendHttpRequest.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/modules/Elsa.Http/Activities/SendHttpRequest.cs b/src/modules/Elsa.Http/Activities/SendHttpRequest.cs index 764c6871f..6b786f51d 100644 --- a/src/modules/Elsa.Http/Activities/SendHttpRequest.cs +++ b/src/modules/Elsa.Http/Activities/SendHttpRequest.cs @@ -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 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); }