summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
fd6dc11)
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.
/**
* Get the contents from a URL.
*/
/**
* 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,
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_HEADER => FALSE,
CURLOPT_COOKIEFILE => "",
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => ['Accept-language: en'],
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);
]);
$contents = Tweeper::curlExec($ch);
curl_close($ch);
/**
* Get the headers from a URL.
*/
/**
* 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,
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_HEADER => TRUE,
// Follow http redirects to get the real URL.
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
// 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);
]);
$ret = Tweeper::curlExec($ch);