diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-07-05 17:51:23 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-05 17:51:23 -0500 |
| commit | 8551ea1930b6639007d18fdca35bfb4073b16914 (patch) | |
| tree | 2430f701f8359e602f4c16847331c588cb473cca /src/slskd/Integrations/Webhooks | |
| parent | 8ab0cda52fda8b7e4f0353065c6f0dc5caeeb1f1 (diff) | |
| parent | 4914c3832358218d28f977baed2ddfb1e7e92723 (diff) | |
| download | slskd-8551ea1930b6639007d18fdca35bfb4073b16914.tar.gz | |
Merge branch 'master' into dependabot/npm_and_yarn/src/web/http-proxy-middleware-2.0.9
Diffstat (limited to 'src/slskd/Integrations/Webhooks')
| -rw-r--r-- | src/slskd/Integrations/Webhooks/WebhookService.cs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/slskd/Integrations/Webhooks/WebhookService.cs b/src/slskd/Integrations/Webhooks/WebhookService.cs index 62f097b7..b08b0484 100644 --- a/src/slskd/Integrations/Webhooks/WebhookService.cs +++ b/src/slskd/Integrations/Webhooks/WebhookService.cs @@ -25,6 +25,9 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Text; +using System.Text.Encodings.Web; +using System.Text.Json; +using System.Text.Json.Serialization; using System.Threading.Tasks; using Serilog; using slskd.Events; @@ -40,6 +43,15 @@ public class WebhookService OptionsMonitor = optionsMonitor; HttpClientFactory = httpClientFactory; + var json = new JsonSerializerOptions(); + json.Converters.Add(new IPAddressConverter()); + json.Converters.Add(new JsonStringEnumConverter()); + json.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; + json.DefaultIgnoreCondition = JsonIgnoreCondition.Never; // include properties with null values + json.Encoder = JavaScriptEncoder.Default; // IMPORTANT! don't change this to 'UnsafeRelaxedJsonEscaping'; as the name implies, it's unsafe! + + JsonSerializerOptions = json; + Events.Subscribe<Event>(nameof(WebhookService), HandleEvent); Log.Debug("{Service} initialized", nameof(WebhookService)); @@ -49,6 +61,7 @@ public class WebhookService private IOptionsMonitor<Options> OptionsMonitor { get; } private EventBus Events { get; } private IHttpClientFactory HttpClientFactory { get; } + private JsonSerializerOptions JsonSerializerOptions { get; } private async Task HandleEvent(Event data) { @@ -80,7 +93,10 @@ public class WebhookService http.DefaultRequestHeaders.TryAddWithoutValidation(header.Name, header.Value); } - var content = new StringContent(data.ToJson(), Encoding.UTF8, "application/json"); + var content = new StringContent( + content: JsonSerializer.Serialize(data, JsonSerializerOptions), + encoding: Encoding.UTF8, + mediaType: "application/json"); HttpStatusCode? statusCode = null; |
