Add functionality to call a PostTransform method after the Webhook request has been transformed (#1223)

* Add functionality to call a PostTransform method after the Webhook request has been transformed

* UseTransformer == true
This commit is contained in:
Stef Heyenrath
2024-12-22 18:38:12 +01:00
committed by GitHub
parent 6db5427e6e
commit c4ae4eaf8e
2 changed files with 21 additions and 5 deletions

View File

@@ -46,7 +46,7 @@ internal class WebhookSender
IBodyData? bodyData;
IDictionary<string, WireMockList<string>>? headers;
string webhookRequestUrl;
string requestUrl;
if (webhookRequest.UseTransformer == true)
{
ITransformer transformer;
@@ -69,18 +69,20 @@ internal class WebhookSender
bodyData = transformer.TransformBody(mapping, originalRequestMessage, originalResponseMessage, webhookRequest.BodyData, webhookRequest.TransformerReplaceNodeOptions);
headers = transformer.TransformHeaders(mapping, originalRequestMessage, originalResponseMessage, webhookRequest.Headers);
webhookRequestUrl = transformer.TransformString(mapping, originalRequestMessage, originalResponseMessage, webhookRequest.Url);
requestUrl = transformer.TransformString(mapping, originalRequestMessage, originalResponseMessage, webhookRequest.Url);
mapping.Settings.WebhookSettings?.PostTransform(mapping, requestUrl, bodyData, headers);
}
else
{
bodyData = webhookRequest.BodyData;
headers = webhookRequest.Headers;
webhookRequestUrl = webhookRequest.Url;
requestUrl = webhookRequest.Url;
}
// Create RequestMessage
var requestMessage = new RequestMessage(
new UrlDetails(webhookRequestUrl),
new UrlDetails(requestUrl),
webhookRequest.Method,
ClientIp,
bodyData,
@@ -91,7 +93,7 @@ internal class WebhookSender
};
// Create HttpRequestMessage
var httpRequestMessage = HttpRequestMessageHelper.Create(requestMessage, webhookRequestUrl);
var httpRequestMessage = HttpRequestMessageHelper.Create(requestMessage, requestUrl);
// Delay (if required)
if (TryGetDelay(webhookRequest, out var delay))

View File

@@ -1,5 +1,9 @@
// Copyright © WireMock.Net
using System.Collections.Generic;
using WireMock.Types;
using WireMock.Util;
namespace WireMock.Settings;
/// <summary>
@@ -7,4 +11,14 @@ namespace WireMock.Settings;
/// </summary>
public class WebhookSettings : HttpClientSettings
{
/// <summary>
/// Executes an action after the transformation of the request body.
/// </summary>
/// <param name="mapping">The mapping used for the request.</param>
/// <param name="requestUrl">The request Url.</param>
/// <param name="bodyData">The body data of the request. [Optional]</param>
/// <param name="headers">The headers of the request. [Optional]</param>
public virtual void PostTransform(IMapping mapping, string requestUrl, IBodyData? bodyData = null, IDictionary<string, WireMockList<string>>? headers = null)
{
}
}