Webhook
This commit is contained in:
Stef Heyenrath
2021-03-24 18:15:31 +01:00
committed by GitHub
parent cee73023c7
commit d758301e4f
38 changed files with 1206 additions and 338 deletions

View File

@@ -53,7 +53,7 @@ namespace WireMock.Owin.Mappers
}
}
BodyData body = null;
IBodyData body = null;
if (request.Body != null && BodyParser.ShouldParseBody(method, options.AllowBodyForAllHttpMethods == true))
{
var bodyParserSettings = new BodyParserSettings

View File

@@ -9,6 +9,7 @@ using WireMock.Serialization;
using WireMock.Types;
using WireMock.Validation;
using WireMock.ResponseBuilders;
using WireMock.Settings;
#if !USE_ASPNETCORE
using Microsoft.Owin;
using IContext = Microsoft.Owin.IOwinContext;
@@ -153,6 +154,11 @@ namespace WireMock.Owin
{
UpdateScenarioState(targetMapping);
}
if (!targetMapping.IsAdminInterface && targetMapping.Webhook != null)
{
await SendToWebhookAsync(targetMapping, request, response).ConfigureAwait(false);
}
}
catch (Exception ex)
{
@@ -184,6 +190,21 @@ namespace WireMock.Owin
await CompletedTask;
}
private async Task SendToWebhookAsync(IMapping mapping, RequestMessage request, ResponseMessage response)
{
var httpClientForWebhook = HttpClientBuilder.Build(mapping.Settings.WebhookSettings ?? new WebhookSettings());
var webhookSender = new WebhookSender(mapping.Settings);
try
{
await webhookSender.SendAsync(httpClientForWebhook, mapping.Webhook.Request, request, response).ConfigureAwait(false);
}
catch (Exception ex)
{
_options.Logger.Error($"Sending message to Webhook Mapping '{mapping.Guid}' failed. Exception: {ex}");
}
}
private void UpdateScenarioState(IMapping mapping)
{
var scenario = _options.Scenarios[mapping.Scenario];