From: Antonio Ospite Date: Tue, 9 Jun 2020 22:27:35 +0000 (+0200) Subject: src/Tweeper.php: allow overriding the User-Agent in cURL requests X-Git-Tag: v1.4.2~3 X-Git-Url: https://git.ao2.it/tweeper.git/commitdiff_plain/50e34cbbe2a9a8d993f0bba6206b01fcc0e1bad3 src/Tweeper.php: allow overriding the User-Agent in cURL requests Allow overriding the User-Agent in cURL requests, to make it possible to use different user agents for different requests. This can be useful to have a finer control on the version of the site served by the different supported services. --- diff --git a/src/Tweeper.php b/src/Tweeper.php index 091b030..b794368 100644 --- a/src/Tweeper.php +++ b/src/Tweeper.php @@ -157,7 +157,7 @@ class Tweeper { /** * Get the contents from a URL. */ - private static function getUrlContents($url) { + private static function getUrlContents($url, $user_agent = NULL) { $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_HEADER => FALSE, @@ -167,7 +167,7 @@ class Tweeper { CURLOPT_COOKIEFILE => "", CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HTTPHEADER => ['Accept-language: en'], - CURLOPT_USERAGENT => Tweeper::$userAgent, + CURLOPT_USERAGENT => isset($user_agent) ? $user_agent : Tweeper::$userAgent, ]); $contents = Tweeper::curlExec($ch); curl_close($ch); @@ -178,7 +178,7 @@ class Tweeper { /** * Get the headers from a URL. */ - private static function getUrlInfo($url) { + private static function getUrlInfo($url, $user_agent = NULL) { $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_HEADER => TRUE, @@ -187,7 +187,7 @@ class Tweeper { // Follow http redirects to get the real URL. CURLOPT_FOLLOWLOCATION => TRUE, CURLOPT_RETURNTRANSFER => TRUE, - CURLOPT_USERAGENT => Tweeper::$userAgent, + CURLOPT_USERAGENT => isset($user_agent) ? $user_agent : Tweeper::$userAgent, ]); $ret = Tweeper::curlExec($ch);