mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-03-15 12:53:29 +00:00
Correctly set content type when specified in pollin headers
This commit is contained in:
parent
b96a96155d
commit
9c40d17268
2 changed files with 26 additions and 1 deletions
|
|
@ -192,8 +192,12 @@ class Plugin extends Model
|
||||||
$httpRequest = Http::withHeaders($headers);
|
$httpRequest = Http::withHeaders($headers);
|
||||||
|
|
||||||
if ($this->polling_verb === 'post' && $this->polling_body) {
|
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);
|
$resolvedBody = $this->resolveLiquidVariables($this->polling_body);
|
||||||
$httpRequest = $httpRequest->withBody($resolvedBody);
|
$httpRequest = $httpRequest->withBody($resolvedBody, $contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,27 @@ test('updateDataPayload sends POST request with body when polling_verb is post',
|
||||||
$request->body() === '{"query": "query { user { id name } }"}');
|
$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 {
|
test('updateDataPayload handles multiple URLs with IDX_ prefixes', function (): void {
|
||||||
$plugin = Plugin::factory()->create([
|
$plugin = Plugin::factory()->create([
|
||||||
'data_strategy' => 'polling',
|
'data_strategy' => 'polling',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue