mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-03-14 12:23:33 +00:00
Correctly set content type when specified in pollin headers
Some checks are pending
tests / ci (push) Waiting to run
Some checks are pending
tests / ci (push) Waiting to run
This commit is contained in:
parent
344286a5d3
commit
0aa38428f6
2 changed files with 26 additions and 1 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue