use HttpClient first

This commit is contained in:
Jean-Christian Denis 2023-08-12 11:48:55 +02:00
parent 4750d43c55
commit 2441981717
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951

View file

@ -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);