Add Http Response Behavior to answer synchronously using the HttpResponse Activity (#5446)
* Update WriteHttpResponse.cs to call response.CompleteAsync() * Add options in HttpActivityOptions --------- Co-authored-by: Ciaran ODonnell <wannabedeveloper@live.com> Co-authored-by: Jérémie DEVILLARD <jdevillard@users.noreply.github.com>
This commit is contained in:
parent
17c20c53f7
commit
ad236f626f
|
|
@ -10,6 +10,8 @@ using Elsa.Workflows.UIHints;
|
|||
using Elsa.Workflows.Exceptions;
|
||||
using Elsa.Workflows.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Elsa.Http.Options;
|
||||
|
||||
namespace Elsa.Http;
|
||||
|
||||
|
|
@ -133,7 +135,12 @@ public class WriteHttpResponse : Activity
|
|||
await response.WriteAsync("The response includes a type that cannot be serialized.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Check if the configuration is set to flush immediatly the response to the caller.
|
||||
var options = context.GetRequiredService<IOptions<HttpActivityOptions>>();
|
||||
if (options.Value.WriteHttpResponseSynchronously)
|
||||
await response.CompleteAsync();
|
||||
|
||||
// Complete activity.
|
||||
await context.CompleteActivityAsync();
|
||||
|
|
@ -144,4 +151,4 @@ public class WriteHttpResponse : Activity
|
|||
: content is string
|
||||
? "text/plain"
|
||||
: "application/json";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,5 +35,11 @@ public class HttpActivityOptions
|
|||
"text/html",
|
||||
"text/json",
|
||||
"text/xml",
|
||||
};
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// A boolean to opt-in if you want to call CompleteAsync() in the HttpResponse Activity
|
||||
/// and not waiting for the end of the HttpMiddleware.
|
||||
/// </summary>
|
||||
public Boolean WriteHttpResponseSynchronously { get; set; } = false;
|
||||
}
|
||||
Loading…
Reference in a new issue