Skip to content

Commit

Permalink
Refactor HTTP request handling by removing SendHttpRequestTask
Browse files Browse the repository at this point in the history
SendHttpRequestTask was deleted and its functionality was merged into SendHttpRequestBase. This consolidation led to the addition of StatusCode and ResponseHeaders output fields in SendHttpRequestBase. Another change includes the update in FlowSendHttpRequest to indicate that it's no longer deprecated. Also, HttpHeaders class was extended to accommodate HttpResponseHeaders objects. The consolidation was done to streamline the HTTP request handling process.
  • Loading branch information
sfmskywalker committed Jan 6, 2024
1 parent a950a6d commit 7c632a5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 224 deletions.
5 changes: 1 addition & 4 deletions src/modules/Elsa.Http/Activities/FlowSendHttpRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ namespace Elsa.Http;
/// <summary>
/// Send an HTTP request.
/// </summary>
[Activity("Elsa", "HTTP", "Send an HTTP request. This activity yis deprecated in favor of the SendHttpRequestTask activity", DisplayName = "HTTP Request (flow) [Deprecated] ", Kind = ActivityKind.Task)]
[Obsolete("Use SendHttpRequestTask instead.")]
[Activity("Elsa", "HTTP", "Send an HTTP request.", DisplayName = "HTTP Request (flow)", Kind = ActivityKind.Task)]
public class FlowSendHttpRequest : SendHttpRequestBase, IActivityPropertyDefaultValueProvider
{
/// <inheritdoc />
Expand Down Expand Up @@ -44,8 +43,6 @@ protected override async ValueTask HandleResponseAsync(ActivityExecutionContext
outcomes.Add(outcome);

outcomes.Add("Done");

context.JournalData["StatusCode"] = statusCode;
await context.CompleteActivityWithOutcomesAsync(outcomes.ToArray());
}

Expand Down
17 changes: 17 additions & 0 deletions src/modules/Elsa.Http/Activities/SendHttpRequestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,24 @@ protected SendHttpRequestBase(string? source = default, int? line = default) : b
)]
public Input<HttpHeaders?> RequestHeaders { get; set; } = new(new HttpHeaders());

/// <summary>
/// The HTTP response status code
/// </summary>
[Output(Description = "The HTTP response status code")]
public Output<int> StatusCode { get; set; } = default!;

/// <summary>
/// The parsed content, if any.
/// </summary>
[Output(Description = "The parsed content, if any.")]
public Output<object?> ParsedContent { get; set; } = default!;

/// <summary>
/// The response headers that were received.
/// </summary>
[Output(Description = "The response headers that were received.")]
public Output<HttpHeaders?> ResponseHeaders { get; set; } = default!;

/// <inheritdoc />
protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
{
Expand Down Expand Up @@ -115,8 +127,13 @@ private async Task TrySendAsync(ActivityExecutionContext context)
{
var response = await httpClient.SendAsync(request, cancellationToken);
var parsedContent = await ParseContentAsync(context, response.Content);
var statusCode = (int)response.StatusCode;
var responseHeaders = new HttpHeaders(response.Headers);

context.Set(Result, response);
context.Set(ParsedContent, parsedContent);
context.Set(StatusCode, statusCode);
context.Set(ResponseHeaders, responseHeaders);

await HandleResponseAsync(context, response);
}
Expand Down
220 changes: 0 additions & 220 deletions src/modules/Elsa.Http/Activities/SendHttpRequestTask.cs

This file was deleted.

20 changes: 20 additions & 0 deletions src/modules/Elsa.Http/Models/HttpHeaders.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Net.Http.Headers;
using System.Text.Json.Serialization;
using Elsa.Extensions;
using Elsa.Http.Serialization;
Expand All @@ -10,6 +11,25 @@ namespace Elsa.Http.Models;
[JsonConverter(typeof(HttpHeadersConverter))]
public class HttpHeaders : Dictionary<string, string[]>
{
/// <inheritdoc />
public HttpHeaders()
{
}

/// <inheritdoc />
public HttpHeaders(IDictionary<string, string[]> source)
{
foreach (var item in source)
Add(item.Key, item.Value);
}

/// <inheritdoc />
public HttpHeaders(HttpResponseHeaders source)
{
foreach (var item in source)
Add(item.Key, item.Value.ToArray());
}

/// <summary>
/// Gets the content type.
/// </summary>
Expand Down

0 comments on commit 7c632a5

Please sign in to comment.