feat: custom http ua in AO3, fix #3188 (#3189)

* refactor

* feat: custom http ua in AO3, #3188
This commit is contained in:
Dag 2022-12-13 09:53:42 +01:00 committed by GitHub
parent 933be15a77
commit a13c4624fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 28 deletions

View file

@ -125,6 +125,8 @@ function getContents(
$httpHeadersNormalized[$headerName] = $headerValue;
}
$config = [
'useragent' => Configuration::getConfig('http', 'useragent'),
'timeout' => Configuration::getConfig('http', 'timeout'),
'headers' => array_merge($defaultHttpHeaders, $httpHeadersNormalized),
'curl_options' => $curlOptions,
];
@ -215,8 +217,8 @@ function getContents(
function _http_request(string $url, array $config = []): array
{
$defaults = [
'useragent' => Configuration::getConfig('http', 'useragent'),
'timeout' => Configuration::getConfig('http', 'timeout'),
'useragent' => null,
'timeout' => 5,
'headers' => [],
'proxy' => null,
'curl_options' => [],
@ -236,7 +238,9 @@ function _http_request(string $url, array $config = []): array
$httpHeaders[] = sprintf('%s: %s', $name, $value);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
curl_setopt($ch, CURLOPT_USERAGENT, $config['useragent']);
if ($config['useragent']) {
curl_setopt($ch, CURLOPT_USERAGENT, $config['useragent']);
}
curl_setopt($ch, CURLOPT_TIMEOUT, $config['timeout']);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);