diff --git a/src/modules/Elsa.Http/Activities/WriteHttpResponse.cs b/src/modules/Elsa.Http/Activities/WriteHttpResponse.cs index 6e7ef8d0c..eb7af41d8 100644 --- a/src/modules/Elsa.Http/Activities/WriteHttpResponse.cs +++ b/src/modules/Elsa.Http/Activities/WriteHttpResponse.cs @@ -1,5 +1,6 @@ using System.Net; using System.Net.Mime; +using System.Text.Json.Nodes; using Elsa.Extensions; using Elsa.Http.ContentWriters; using Elsa.Http.Models; @@ -94,7 +95,7 @@ public class WriteHttpResponse : CodeActivity if (content == null) return; - var contentType = ContentType.TryGet(context) ?? MediaTypeNames.Text.Plain; + var contentType = ContentType.TryGet(context); if (string.IsNullOrWhiteSpace(contentType)) contentType = DetermineContentType(content); @@ -109,5 +110,9 @@ public class WriteHttpResponse : CodeActivity await httpContent.CopyToAsync(response.Body); } - private string DetermineContentType(object? content) => content is byte[] or Stream ? "application/octet-stream" : "text/plain"; + private string DetermineContentType(object? content) => content is byte[] or Stream + ? "application/octet-stream" + : content is string + ? "text/plain" + : "application/json"; } \ No newline at end of file diff --git a/src/modules/Elsa.Http/ContentWriters/TextContentFactory.cs b/src/modules/Elsa.Http/ContentWriters/TextContentFactory.cs index 38aa15412..ff43ed656 100644 --- a/src/modules/Elsa.Http/ContentWriters/TextContentFactory.cs +++ b/src/modules/Elsa.Http/ContentWriters/TextContentFactory.cs @@ -21,11 +21,11 @@ public class TextContentFactory : IHttpContentFactory /// public HttpContent CreateHttpContent(object content, string contentType) { - var text = content as string ?? ""; + var text = content as string ?? content.ToString(); if (string.IsNullOrWhiteSpace(contentType)) contentType = MediaTypeNames.Text.Plain; - return new StringContent(text, Encoding.UTF8, contentType); + return new StringContent(text!, Encoding.UTF8, contentType); } } \ No newline at end of file