diff --git a/src/App.php b/src/App.php index 9b6f6a5a2..65ae3fe2f 100644 --- a/src/App.php +++ b/src/App.php @@ -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. * diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 9d9679c49..036bc4a27 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -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); diff --git a/src/Network/HTTPRequest.php b/src/Network/HTTPRequest.php index ac2d70cad..1a0048b2a 100644 --- a/src/Network/HTTPRequest.php +++ b/src/Network/HTTPRequest.php @@ -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; + } } diff --git a/src/Util/Network.php b/src/Util/Network.php index 888dc20a6..a8b216b34 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -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);