From f125bb857748761cc16be874f3898fba32a0d77a Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:35:02 +0800 Subject: [PATCH 1/2] Optimize config of GuzzleHttpClient --- src/Transporter/GuzzleHttpTransporter.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Transporter/GuzzleHttpTransporter.php b/src/Transporter/GuzzleHttpTransporter.php index 57af769..dc8659e 100644 --- a/src/Transporter/GuzzleHttpTransporter.php +++ b/src/Transporter/GuzzleHttpTransporter.php @@ -37,15 +37,14 @@ public function __construct(string $host = '', int $port = 9501, array $config = { parent::__construct($host, $port); - $this->config = array_merge_recursive($config, [ - 'headers' => [ - 'Content-Type' => 'application/json', - 'X-Real-Ip' => $_SERVER['SERVER_ADDR'] ?? '', - 'X-Forwarded-For' => $_SERVER['REMOTE_ADDR'] ?? '', - 'User-Agent' => UserAgent::get(), - ], - 'http_errors' => false, - ]); + $this->config['headers'] = array_replace([ + 'Content-Type' => 'application/json', + 'X-Real-Ip' => $_SERVER['SERVER_ADDR'] ?? '', + 'X-Forwarded-For' => $_SERVER['REMOTE_ADDR'] ?? '', + 'User-Agent' => UserAgent::get(), + ], $config['headers'] ?? []); + $this->config['http_errors'] ??= false; + $this->config['timeout'] ??= $this->timeout; } public function send(string $data) From a0a6fd2c33128b396a2394971ff242808d92ee82 Mon Sep 17 00:00:00 2001 From: Deeka Wong <8337659+huangdijia@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:37:10 +0800 Subject: [PATCH 2/2] feat: Update GuzzleHttpTransporter configuration handling The code changes in `GuzzleHttpTransporter.php` update the configuration handling in the constructor. The `$config` array is now merged with a default configuration array using `array_replace()`. This change ensures that the transporter has the correct configuration values when creating a new instance of `GuzzleHttpTransporter`. Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com> --- src/Transporter/GuzzleHttpTransporter.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Transporter/GuzzleHttpTransporter.php b/src/Transporter/GuzzleHttpTransporter.php index dc8659e..192eec6 100644 --- a/src/Transporter/GuzzleHttpTransporter.php +++ b/src/Transporter/GuzzleHttpTransporter.php @@ -43,8 +43,10 @@ public function __construct(string $host = '', int $port = 9501, array $config = 'X-Forwarded-For' => $_SERVER['REMOTE_ADDR'] ?? '', 'User-Agent' => UserAgent::get(), ], $config['headers'] ?? []); - $this->config['http_errors'] ??= false; - $this->config['timeout'] ??= $this->timeout; + $this->config = array_replace([ + 'http_errors' => false, + 'timeout' => $this->timeout, + ], $config); } public function send(string $data)