Correctly set content type when specified in pollin headers
Some checks are pending
tests / ci (push) Waiting to run

This commit is contained in:
Jamie Shiell 2026-02-08 15:37:41 +00:00 committed by Benjamin Nussbaum
parent 344286a5d3
commit 0aa38428f6
2 changed files with 26 additions and 1 deletions

View file

@ -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 {

View file

@ -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' => '<query><user id="123" name="John Doe"/></query>',
'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() === '<query><user id="123" name="John Doe"/></query>');
});
test('updateDataPayload handles multiple URLs with IDX_ prefixes', function (): void {
$plugin = Plugin::factory()->create([
'data_strategy' => 'polling',