From 32d6f903c5c297805047c6710e92002356336572 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 3 Oct 2025 18:44:38 +0100 Subject: [PATCH] Resolves Workflow Execution Bodiless Requests Issue. (#6944) * Resolves workflow execution bodiless requests issue. Removed content length check when processing JSON requests, relying solely on content type validation. Added a null-check for deserialized requests to handle cases where the request body is missing or invalid, providing a specific error message. * Refactor JSON request handling in PostEndpoint Updated to get unit tests to pass. --- .../Execute/PostEndpoint.cs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Execute/PostEndpoint.cs b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Execute/PostEndpoint.cs index 6f787ae4d..4081bc4dc 100644 --- a/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Execute/PostEndpoint.cs +++ b/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Execute/PostEndpoint.cs @@ -30,19 +30,24 @@ internal class PostEndpoint( { PostRequest? request = null; - if (HttpContext.Request.ContentLength > 0 && (HttpContext.Request.ContentType?.Contains("application/json") ?? true)) + if (HttpContext.Request.ContentType?.Contains("application/json") ?? false) { - try + using var reader = new StreamReader(HttpContext.Request.Body); + var body = await reader.ReadToEndAsync(); + + if (!string.IsNullOrWhiteSpace(body)) { - request = await JsonSerializer.DeserializeAsync(HttpContext.Request.Body, - new JsonSerializerOptions + try { - PropertyNameCaseInsensitive = true - }, cancellationToken: cancellationToken); - } - catch - { - AddError("Invalid request body."); + request = JsonSerializer.Deserialize(body, new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true + }); + } + catch + { + AddError("Invalid request body."); + } } }