2022-01-04 08:42:12 +00:00
|
|
|
using System.Net;
|
|
|
|
|
using System.Threading.Tasks;
|
2022-05-03 07:46:27 +00:00
|
|
|
using Elsa.Attributes;
|
2022-01-04 08:42:12 +00:00
|
|
|
using Elsa.Models;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
2022-02-01 19:45:11 +00:00
|
|
|
namespace Elsa.Modules.Http;
|
2022-01-04 08:42:12 +00:00
|
|
|
|
2022-05-03 07:46:27 +00:00
|
|
|
[Activity("Elsa", "HTTP", "Write an HTTP response.")]
|
2022-01-04 08:42:12 +00:00
|
|
|
public class WriteHttpResponse : Activity
|
|
|
|
|
{
|
|
|
|
|
public Input<HttpStatusCode> StatusCode { get; set; } = new(HttpStatusCode.OK);
|
|
|
|
|
public Input<string?> Content { get; set; } = new("");
|
|
|
|
|
|
2022-01-26 14:48:59 +00:00
|
|
|
protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
|
2022-01-04 08:42:12 +00:00
|
|
|
{
|
|
|
|
|
var httpContextAccessor = context.GetRequiredService<IHttpContextAccessor>();
|
|
|
|
|
var httpContext = httpContextAccessor.HttpContext;
|
|
|
|
|
var response = httpContext.Response;
|
|
|
|
|
|
|
|
|
|
response.StatusCode = (int)context.Get(StatusCode);
|
|
|
|
|
|
|
|
|
|
var content = context.Get(Content);
|
|
|
|
|
|
|
|
|
|
if (content != null)
|
|
|
|
|
await response.WriteAsync(content, context.CancellationToken);
|
|
|
|
|
}
|
|
|
|
|
}
|