diff --git a/src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs b/src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs index 4dbb232..4eb40ab 100644 --- a/src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs +++ b/src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs @@ -9,7 +9,7 @@ public class BodyQueryBehavior(IRecDbContext dbContext) : IPipelineB where TRecAction : RecActionDto { public async Task Handle(TRecAction action, RequestHandlerDelegate next, CancellationToken cancel) - { + { if (action.BodyQuery is null) return await next(cancel); diff --git a/src/ReC.Application/Common/Behaviors/HeaderQueryBehavior.cs b/src/ReC.Application/Common/Behaviors/HeaderQueryBehavior.cs index 32d5c15..1b14bd7 100644 --- a/src/ReC.Application/Common/Behaviors/HeaderQueryBehavior.cs +++ b/src/ReC.Application/Common/Behaviors/HeaderQueryBehavior.cs @@ -18,13 +18,24 @@ public class HeaderQueryBehavior(IRecDbContext dbContext, ILogger>(result.RawHeader); if(headerDict is null) { - logger?.LogWarning("Failed to deserialize header query result: {RawHeader}. Profile ID: {ProfileId}, Action ID: {ActionId}", result.RawHeader, action.ProfileId, action.ActionId); + logger?.LogWarning( + "Header JSON deserialization returned null. RawHeader: {RawHeader}, ProfileId: {ProfileId}, ActionId: {ActionId}", + result.RawHeader, action.ProfileId, action.ActionId); + + action.IsReturnedNoData.HeaderQuery = true; + return await next(cancel); } diff --git a/src/ReC.Application/Common/Dto/RecActionDto.cs b/src/ReC.Application/Common/Dto/RecActionDto.cs index f636510..76af15f 100644 --- a/src/ReC.Application/Common/Dto/RecActionDto.cs +++ b/src/ReC.Application/Common/Dto/RecActionDto.cs @@ -60,6 +60,8 @@ public record RecActionDto public string? Body { get; set; } + public (bool BodyQuery, bool HeaderQuery) IsReturnedNoData = (false, false); + public string? PostprocessingQuery { get; init; } public UriBuilder ToEndpointUriBuilder() diff --git a/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs b/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs index f40ea25..be24672 100644 --- a/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs +++ b/src/ReC.Application/RecActions/Commands/InvokeRecActionCommand.cs @@ -40,6 +40,27 @@ public class InvokeRecActionCommandHandler( .ToHttpMethod() .ToHttpRequestMessage(request.EndpointUri); + if(request.Body is not null) + { + using var reqBody = new StringContent(request.Body); + httpReq.Content = reqBody; + } + else if(request.BodyQuery is not null && !request.IsReturnedNoData.BodyQuery) + { + logger?.LogWarning( + "Although BodyQuery returns null, the IsReturnedNoData variable has not been set to TRUE. " + + "This indicates that BodyQueryBehavior has not been executed or that the relevant control step has been skipped. " + + "The relevant behavior must be verified to ensure that the process does not produce unexpected conditions. " + + "ProfileId: {ProfileId}, ActionId: {ActionId}", + request.ProfileId, + request.ActionId + ); + } + + if (request.Headers is not null) + foreach (var header in request.Headers) + httpReq.Headers.Add(header.Key, header.Value); + using var response = await http.SendAsync(httpReq, cancel); var body = await response.Content.ReadAsStringAsync(cancel); var headers = response.Headers.ToDictionary();