From 6a7e956895897587a7a2c0639b5d12ebd8462810 Mon Sep 17 00:00:00 2001 From: Samuel Melrose Date: Fri, 13 Sep 2024 11:22:27 +0000 Subject: [PATCH] Tasks: Support JSON via PushTask --- .../Integration/TaskQueue/PushTask.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/AffordableMobiles/GServerlessSupportLaravel/Integration/TaskQueue/PushTask.php b/src/AffordableMobiles/GServerlessSupportLaravel/Integration/TaskQueue/PushTask.php index 1731067..3167c22 100755 --- a/src/AffordableMobiles/GServerlessSupportLaravel/Integration/TaskQueue/PushTask.php +++ b/src/AffordableMobiles/GServerlessSupportLaravel/Integration/TaskQueue/PushTask.php @@ -66,10 +66,21 @@ public function __construct($url_path, $query_data = [], $options = []) } } - $this->pushTask->setBody(http_build_query($query_data)); - $this->pushTask->setHeaders([ - 'Content-Type' => 'application/x-www-form-urlencoded', - ]); + if ($options['json'] ?? false) { + $this->pushTask->setBody( + json_encode($query_data, JSON_PRETTY_PRINT), + ); + $this->pushTask->setHeaders([ + 'Content-Type' => 'application/json', + ]); + } else { + $this->pushTask->setBody( + http_build_query($query_data), + ); + $this->pushTask->setHeaders([ + 'Content-Type' => 'application/x-www-form-urlencoded', + ]); + } if (!empty($options['method'])) { $this->pushTask->setHttpMethod(