Introduce "accept_header" as specific argument to the http client
This commit is contained in:
parent
73c3b21665
commit
e299fc67c8
35 changed files with 150 additions and 150 deletions
|
@ -304,7 +304,7 @@ class HTTPSignature
|
|||
|
||||
$headers['Content-Type'] = 'application/activity+json';
|
||||
|
||||
$postResult = DI::httpClient()->post($target, $content, $headers);
|
||||
$postResult = DI::httpClient()->post($target, $content, HttpClientAccept::DEFAULT, $headers);
|
||||
$return_code = $postResult->getReturnCode();
|
||||
|
||||
Logger::info('Transmit to ' . $target . ' returned ' . $return_code);
|
||||
|
@ -452,9 +452,9 @@ class HTTPSignature
|
|||
$curl_opts[HttpClientOptions::HEADERS] = $header;
|
||||
|
||||
if (!empty($opts['nobody'])) {
|
||||
$curlResult = DI::httpClient()->head($request, $curl_opts);
|
||||
$curlResult = DI::httpClient()->head($request, HttpClientAccept::JSON_AS, $curl_opts);
|
||||
} else {
|
||||
$curlResult = DI::httpClient()->get($request, $curl_opts);
|
||||
$curlResult = DI::httpClient()->get($request, HttpClientAccept::JSON_AS, $curl_opts);
|
||||
}
|
||||
$return_code = $curlResult->getReturnCode();
|
||||
|
||||
|
|
|
@ -220,7 +220,7 @@ class Images
|
|||
}
|
||||
|
||||
if (empty($img_str)) {
|
||||
$img_str = DI::httpClient()->fetch($url, 4, HttpClientAccept::IMAGE);
|
||||
$img_str = DI::httpClient()->fetch($url, HttpClientAccept::IMAGE, 4);
|
||||
}
|
||||
|
||||
if (!$img_str) {
|
||||
|
|
|
@ -61,11 +61,11 @@ class ParseUrl
|
|||
*/
|
||||
public static function getContentType(string $url, string $accept = HttpClientAccept::DEFAULT)
|
||||
{
|
||||
$curlResult = DI::httpClient()->head($url, [HttpClientOptions::ACCEPT_CONTENT => $accept]);
|
||||
$curlResult = DI::httpClient()->head($url, $accept);
|
||||
|
||||
// Workaround for systems that can't handle a HEAD request
|
||||
if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) {
|
||||
$curlResult = DI::httpClient()->get($url, [HttpClientOptions::CONTENT_LENGTH => 1000000, HttpClientOptions::ACCEPT_CONTENT => $accept]);
|
||||
$curlResult = DI::httpClient()->get($url, $accept, [HttpClientOptions::CONTENT_LENGTH => 1000000]);
|
||||
}
|
||||
|
||||
if (!$curlResult->isSuccess()) {
|
||||
|
@ -222,7 +222,7 @@ class ParseUrl
|
|||
return $siteinfo;
|
||||
}
|
||||
|
||||
$curlResult = DI::httpClient()->get($url, [HttpClientOptions::CONTENT_LENGTH => 1000000, HttpClientOptions::ACCEPT_CONTENT => HttpClientAccept::HTML]);
|
||||
$curlResult = DI::httpClient()->get($url, HttpClientAccept::HTML, [HttpClientOptions::CONTENT_LENGTH => 1000000]);
|
||||
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
|
||||
Logger::info('Empty body or error when fetching', ['url' => $url, 'success' => $curlResult->isSuccess(), 'code' => $curlResult->getReturnCode()]);
|
||||
return $siteinfo;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue