From 244198171777a51097f0f1ad9bf91c153068c690 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 12 Aug 2023 11:48:55 +0200 Subject: [PATCH] use HttpClient first --- src/Utils.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Utils.php b/src/Utils.php index 239078b..97fbe6a 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -192,9 +192,18 @@ class Utils $status = 500; $response = ''; $url = sprintf(self::url(), 'report'); + $path = ''; try { - if (function_exists('curl_init')) { + if (false !== ($client = HttpClient::initClient($url, $path))) { + $client->setUserAgent('Dotclear.watch ' . My::id() . '/' . self::DISTANT_API_VERSION); + $client->useGzip(false); + $client->setPersistReferers(false); + $client->post($path, ['key' => self::key(), 'report' => $contents]); + + $status = (int) $client->getStatus(); + $response = $client->getContent(); + } elseif (function_exists('curl_init')) { if (false !== ($client = curl_init($url))) { curl_setopt($client, CURLOPT_RETURNTRANSFER, true); curl_setopt($client, CURLOPT_POST, true); @@ -204,17 +213,6 @@ class Utils $status = (int) curl_getinfo($client, CURLINFO_HTTP_CODE); } } - } else { - $path = ''; - if (false !== ($client = HttpClient::initClient($url, $path))) { - $client->setUserAgent('Dotclear.watch ' . My::id() . '/' . self::DISTANT_API_VERSION); - $client->useGzip(false); - $client->setPersistReferers(false); - $client->post($path, ['key' => self::key(), 'report' => $contents]); - - $status = (int) $client->getStatus(); - $response = $client->getContent(); - } } unset($client);