Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/WireMock.Net/Http/WebhookSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ IResponseMessage originalResponseMessage

IBodyData? bodyData;
IDictionary<string, WireMockList<string>>? headers;
string webhookRequestUrl;
string requestUrl;
if (webhookRequest.UseTransformer == true)
{
ITransformer transformer;
Expand All @@ -69,18 +69,20 @@ IResponseMessage originalResponseMessage

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,
Expand All @@ -91,7 +93,7 @@ IResponseMessage originalResponseMessage
};

// Create HttpRequestMessage
var httpRequestMessage = HttpRequestMessageHelper.Create(requestMessage, webhookRequestUrl);
var httpRequestMessage = HttpRequestMessageHelper.Create(requestMessage, requestUrl);

// Delay (if required)
if (TryGetDelay(webhookRequest, out var delay))
Expand Down
14 changes: 14 additions & 0 deletions src/WireMock.Net/Settings/WebhookSettings.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
// Copyright © WireMock.Net

using System.Collections.Generic;
using WireMock.Types;
using WireMock.Util;

namespace WireMock.Settings;

/// <summary>
/// WebhookSettings
/// </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>

Check warning on line 17 in src/WireMock.Net/Settings/WebhookSettings.cs

View check run for this annotation

Codecov / codecov/patch

src/WireMock.Net/Settings/WebhookSettings.cs#L17

Added line #L17 was not covered by tests
/// <param name="requestUrl">The request Url.</param>
/// <param name="bodyData">The body data of the request. [Optional]</param>

Check warning on line 19 in src/WireMock.Net/Settings/WebhookSettings.cs

View check run for this annotation

Codecov / codecov/patch

src/WireMock.Net/Settings/WebhookSettings.cs#L19

Added line #L19 was not covered by tests
/// <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)

Check warning on line 21 in src/WireMock.Net/Settings/WebhookSettings.cs

View check run for this annotation

Codecov / codecov/patch

src/WireMock.Net/Settings/WebhookSettings.cs#L21

Added line #L21 was not covered by tests
{
}
}
Loading