From 0aa38428f693dacf3b0c92760f9238952aa074ba Mon Sep 17 00:00:00 2001 From: Jamie Shiell Date: Sun, 8 Feb 2026 15:37:41 +0000 Subject: [PATCH] Correctly set content type when specified in pollin headers --- app/Models/Plugin.php | 6 +++++- tests/Unit/Models/PluginTest.php | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/Models/Plugin.php b/app/Models/Plugin.php index d377956..fc49f3c 100644 --- a/app/Models/Plugin.php +++ b/app/Models/Plugin.php @@ -192,8 +192,12 @@ class Plugin extends Model $httpRequest = Http::withHeaders($headers); if ($this->polling_verb === 'post' && $this->polling_body) { + $contentType = (array_key_exists('Content-Type', $headers)) + ? $headers['Content-Type'] + : 'application/json'; + $resolvedBody = $this->resolveLiquidVariables($this->polling_body); - $httpRequest = $httpRequest->withBody($resolvedBody); + $httpRequest = $httpRequest->withBody($resolvedBody, $contentType); } try { diff --git a/tests/Unit/Models/PluginTest.php b/tests/Unit/Models/PluginTest.php index 749fb62..82813d9 100644 --- a/tests/Unit/Models/PluginTest.php +++ b/tests/Unit/Models/PluginTest.php @@ -72,6 +72,27 @@ test('updateDataPayload sends POST request with body when polling_verb is post', $request->body() === '{"query": "query { user { id name } }"}'); }); +test('updateDataPayload sends POST request with body with correct content type when not JSON content', function (): void { + Http::fake([ + 'https://example.com/api' => Http::response(['success' => true], 200), + ]); + + $plugin = Plugin::factory()->create([ + 'data_strategy' => 'polling', + 'polling_url' => 'https://example.com/api', + 'polling_verb' => 'post', + 'polling_body' => '', + 'polling_header' => 'Content-Type: text/xml' + ]); + + $plugin->updateDataPayload(); + + Http::assertSent(fn ($request): bool => $request->url() === 'https://example.com/api' && + $request->method() === 'POST' && + $request->hasHeader('Content-Type', 'text/xml') && + $request->body() === ''); +}); + test('updateDataPayload handles multiple URLs with IDX_ prefixes', function (): void { $plugin = Plugin::factory()->create([ 'data_strategy' => 'polling',