From 776851b84fda773c95531fb31d493069e0c8fea1 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 17 Jul 2020 20:41:02 +0000 Subject: [PATCH] User agent added --- src/classes/Pollers/Directory.php | 4 +++- src/classes/Pollers/Server.php | 3 ++- src/classes/Utils/Network.php | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/classes/Pollers/Directory.php b/src/classes/Pollers/Directory.php index 93e2c10..53c0f9e 100644 --- a/src/classes/Pollers/Directory.php +++ b/src/classes/Pollers/Directory.php @@ -2,6 +2,8 @@ namespace Friendica\Directory\Pollers; +use Friendica\Directory\Utils\Network; + /** * @author Hypolite Petovan */ @@ -96,7 +98,7 @@ class Directory CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS, //Basic request - CURLOPT_USERAGENT => 'friendica-directory-probe-1.0', + CURLOPT_USERAGENT => Network::USER_AGENT, CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => $directory_url . $path ); diff --git a/src/classes/Pollers/Server.php b/src/classes/Pollers/Server.php index 58c5c51..2216200 100644 --- a/src/classes/Pollers/Server.php +++ b/src/classes/Pollers/Server.php @@ -3,6 +3,7 @@ namespace Friendica\Directory\Pollers; use ByJG\Util\WebRequest; +use Friendica\Directory\Utils\Network; /** * @author Hypolite Petovan @@ -244,7 +245,7 @@ class Server CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS, //Basic request - CURLOPT_USERAGENT => 'friendica-directory-probe-1.0', + CURLOPT_USERAGENT => Network::USER_AGENT, CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => $base_url . '/friendica/json' ); diff --git a/src/classes/Utils/Network.php b/src/classes/Utils/Network.php index a6170af..14b0c13 100644 --- a/src/classes/Utils/Network.php +++ b/src/classes/Utils/Network.php @@ -15,6 +15,8 @@ namespace Friendica\Directory\Utils; */ class Network { + const USER_AGENT = 'friendica-directory-probe-1.0'; + public static function fetchURL(string $url, bool $binary = false, int $timeout = 20): string { $ch = curl_init($url); @@ -27,6 +29,7 @@ class Network curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 8); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_USERAGENT, self::USER_AGENT); if ($binary) { curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); } @@ -49,6 +52,7 @@ class Network curl_setopt($ch, CURLOPT_MAXREDIRS , 8); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_NOBODY , true); + curl_setopt($ch, CURLOPT_USERAGENT , self::USER_AGENT); curl_exec($ch); -- 2.43.5