Refactor HTTP headers in Elsa

Removed HttpResponseHeaders class and refactored HttpRequestHeaders class into HttpHeaders. This commit merges the separate classes to represent HTTP headers into a single class, HttpHeaders. It also includes updates to the related files like HttpJavaScriptHandler and SendHttpRequestBase to reflect these changes.
This commit is contained in:
Sipke Schoorstra 2023-12-08 21:53:43 +01:00
parent faf8fd1df6
commit cc18e99d24
10 changed files with 18 additions and 35 deletions

View file

@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=downloadables/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=initializable/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=materializers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Populator/@EntryIndexedValue">True</s:Boolean>

View file

@ -5,7 +5,7 @@ using Elsa.Http.ContentWriters;
using Elsa.Workflows.Core;
using Elsa.Workflows.Core.Attributes;
using Elsa.Workflows.Core.Models;
using HttpRequestHeaders = Elsa.Http.Models.HttpRequestHeaders;
using HttpHeaders = Elsa.Http.Models.HttpHeaders;
namespace Elsa.Http;
@ -67,7 +67,7 @@ public abstract class SendHttpRequestBase : Activity<HttpResponseMessage>
/// The headers to send along with the request.
/// </summary>
[Input(Description = "The headers to send along with the request.", Category = "Advanced")]
public Input<HttpRequestHeaders?> RequestHeaders { get; set; } = new(new HttpRequestHeaders());
public Input<HttpHeaders?> RequestHeaders { get; set; } = new(new HttpHeaders());
/// <summary>
/// The parsed content, if any.

View file

@ -49,7 +49,7 @@ public class WriteHttpResponse : Activity
/// The headers to return along with the response.
/// </summary>
[Input(Description = "The headers to send along with the response.", Category = "Advanced")]
public Input<HttpResponseHeaders?> ResponseHeaders { get; set; } = new(new HttpResponseHeaders());
public Input<HttpHeaders?> ResponseHeaders { get; set; } = new(new HttpHeaders());
/// <inheritdoc />
protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)

View file

@ -114,7 +114,7 @@ public class HttpFeature : FeatureBase
typeof(HttpRequest),
typeof(HttpResponse),
typeof(HttpResponseMessage),
typeof(HttpRequestHeaders),
typeof(HttpHeaders),
typeof(IFormFile)
}, "HTTP");

View file

@ -5,13 +5,13 @@ using Elsa.Http.Serialization;
namespace Elsa.Http.Models;
/// <summary>
/// Represents the headers of an HTTP request.
/// Represents the headers of an HTTP message.
/// </summary>
[JsonConverter(typeof(HttpRequestHeadersConverter))]
public class HttpRequestHeaders : Dictionary<string, string[]>
[JsonConverter(typeof(HttpHeadersConverter))]
public class HttpHeaders : Dictionary<string, string[]>
{
/// <summary>
/// Gets the content type of the request.
/// Gets the content type.
/// </summary>
public string? ContentType => this.GetValue("content-type")?[0];
}

View file

@ -1,14 +0,0 @@
using Elsa.Extensions;
namespace Elsa.Http.Models;
/// <summary>
/// Represents the headers of an HTTP response.
/// </summary>
public class HttpResponseHeaders : Dictionary<string, string[]>
{
/// <summary>
/// Gets the content type of the response.
/// </summary>
public string? ContentType => this.GetValue("content-type")?[0];
}

View file

@ -29,7 +29,7 @@ public class HttpJavaScriptHandler : INotificationHandler<EvaluatingJavaScript>,
Task INotificationHandler<EvaluatingJavaScript>.HandleAsync(EvaluatingJavaScript notification, CancellationToken cancellationToken)
{
var engine = notification.Engine;
engine.RegisterType<HttpRequestHeaders>();
engine.RegisterType<HttpHeaders>();
engine.RegisterType<Downloadable>();
var activityExecutionContext = notification.Context;
@ -62,7 +62,7 @@ public class HttpJavaScriptHandler : INotificationHandler<EvaluatingJavaScript>,
private IEnumerable<TypeDefinition> GetTypeDefinitions(TypeDefinitionContext context)
{
yield return _typeDescriber.DescribeType(typeof(HttpRequestHeaders));
yield return _typeDescriber.DescribeType(typeof(HttpHeaders));
yield return _typeDescriber.DescribeType(typeof(Downloadable));
}

View file

@ -4,18 +4,16 @@ using Elsa.Http.Models;
namespace Elsa.Http.Serialization;
/// <summary>
/// A custom JSON converter for <see cref="HttpRequestHeaders"/> that supports both single and multiple values.
/// </summary>
public class HttpRequestHeadersConverter : JsonConverter<HttpRequestHeaders>
/// A custom JSON converter for HttpHeaders that supports both single and multiple values.
public class HttpHeadersConverter : JsonConverter<HttpHeaders>
{
/// <inheritdoc />
public override HttpRequestHeaders Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
public override HttpHeaders Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.StartObject)
throw new JsonException("Expected StartObject token");
var headers = new HttpRequestHeaders();
var headers = new HttpHeaders();
while (reader.Read())
{
@ -53,7 +51,7 @@ public class HttpRequestHeadersConverter : JsonConverter<HttpRequestHeaders>
}
/// <inheritdoc />
public override void Write(Utf8JsonWriter writer, HttpRequestHeaders value, JsonSerializerOptions options)
public override void Write(Utf8JsonWriter writer, HttpHeaders value, JsonSerializerOptions options)
{
writer.WriteStartObject();

View file

@ -4,9 +4,7 @@ using Elsa.Http.Models;
namespace Elsa.Http.Serialization;
/// <summary>
/// A custom JSON converter for <see cref="HttpStatusCodeCase"/> objects when serializing workflow states.
/// </summary>
public class HttpStatusCodeCaseForWorkflowInstanceConverter : JsonConverter<HttpStatusCodeCase>
{
/// <inheritdoc />

View file

@ -1,4 +1,4 @@
using System.Dynamic;
using System.Dynamic;
using System.Net;
using System.Net.Mime;
using Elsa.Expressions.Models;
@ -39,7 +39,7 @@ namespace Elsa.Samples.AspNet.DocumentApproval
Content = new("<h1>Request for Approval Sent</h1><p>Your document has been received and will be reviewed shortly.</p>"),
ContentType = new(MediaTypeNames.Text.Html),
StatusCode = new(HttpStatusCode.OK),
ResponseHeaders = new(new HttpResponseHeaders { ["X-Powered-By"] = new[] { "Elsa 3.0" } })
ResponseHeaders = new(new HttpHeaders { ["X-Powered-By"] = new[] { "Elsa 3.0" } })
},
new Fork
{