Move "getUserAgent()" to "HTTPRequest" class

This commit is contained in:
nupplaPhil 2020-03-04 22:26:38 +01:00 committed by Hypolite Petovan
parent cebdcb6599
commit 57587efe58
4 changed files with 26 additions and 27 deletions

View file

@ -240,22 +240,6 @@ class App
}
}
/**
* Returns the current UserAgent as a String
*
* @return string the UserAgent as a String
* @throws HTTPException\InternalServerErrorException
*/
public function getUserAgent()
{
return
FRIENDICA_PLATFORM . " '" .
FRIENDICA_CODENAME . "' " .
FRIENDICA_VERSION . '-' .
DB_UPDATE_VERSION . '; ' .
$this->baseURL->get();
}
/**
* Returns the current theme name. May be overriden by the mobile theme name.
*

View file

@ -1094,7 +1094,7 @@ class BBCode
$ch = @curl_init($match[1]);
@curl_setopt($ch, CURLOPT_NOBODY, true);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
@curl_setopt($ch, CURLOPT_USERAGENT, DI::httpRequest()->getUserAgent());
@curl_exec($ch);
$curl_info = @curl_getinfo($ch);
@ -1168,7 +1168,7 @@ class BBCode
$ch = @curl_init($match[1]);
@curl_setopt($ch, CURLOPT_NOBODY, true);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
@curl_setopt($ch, CURLOPT_USERAGENT, DI::httpRequest()->getUserAgent());
@curl_exec($ch);
$curl_info = @curl_getinfo($ch);

View file

@ -41,14 +41,14 @@ class HTTPRequest
/** @var IConfig */
private $config;
/** @var string */
private $userAgent;
private $baseUrl;
public function __construct(LoggerInterface $logger, Profiler $profiler, IConfig $config, App $a)
public function __construct(LoggerInterface $logger, Profiler $profiler, IConfig $config, App\BaseURL $baseUrl)
{
$this->logger = $logger;
$this->profiler = $profiler;
$this->config = $config;
$this->userAgent = $a->getUserAgent();
$this->logger = $logger;
$this->profiler = $profiler;
$this->config = $config;
$this->baseUrl = $baseUrl->get();
}
/**
@ -232,7 +232,7 @@ class HTTPRequest
$stamp1 = microtime(true);
if (Network::isUrlBlocked($url)) {
$this->logger->info('Domain is blocked.'. ['url' => $url]);
$this->logger->info('Domain is blocked.' . ['url' => $url]);
return CurlResult::createErrorCurl($url);
}
@ -378,4 +378,19 @@ class HTTPRequest
$redirects
);
}
/**
* Returns the current UserAgent as a String
*
* @return string the UserAgent as a String
*/
public function getUserAgent()
{
return
FRIENDICA_PLATFORM . " '" .
FRIENDICA_CODENAME . "' " .
FRIENDICA_VERSION . '-' .
DB_UPDATE_VERSION . '; ' .
$this->baseUrl;
}
}

View file

@ -350,7 +350,7 @@ class Network
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
curl_setopt($ch, CURLOPT_USERAGENT, DI::httpRequest()->getUserAgent());
curl_exec($ch);
$curl_info = @curl_getinfo($ch);
@ -394,7 +394,7 @@ class Network
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $a->getUserAgent());
curl_setopt($ch, CURLOPT_USERAGENT, DI::httpRequest()->getUserAgent());
$body = curl_exec($ch);
curl_close($ch);