Merge pull request #11389 from nupplaphil/feat/http_client_arg
Introduce explicit HttpClient "Accept" parameter
This commit is contained in:
commit
4eecf733e1
37 changed files with 231 additions and 205 deletions
|
@ -28,7 +28,7 @@ use Friendica\DI;
|
|||
use Friendica\Model\APContact;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Network\HTTPClient\Client\HttpClient;
|
||||
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
||||
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
||||
|
||||
/**
|
||||
|
@ -416,7 +416,7 @@ class HTTPSignature
|
|||
* @return \Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses CurlResult
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function fetchRaw($request, $uid = 0, $opts = [HttpClientOptions::ACCEPT_CONTENT => [HttpClient::ACCEPT_JSON_AS]])
|
||||
public static function fetchRaw($request, $uid = 0, $opts = [HttpClientOptions::ACCEPT_CONTENT => [HttpClientAccept::JSON_AS]])
|
||||
{
|
||||
$header = [];
|
||||
|
||||
|
@ -454,7 +454,7 @@ class HTTPSignature
|
|||
if (!empty($opts['nobody'])) {
|
||||
$curlResult = DI::httpClient()->head($request, $curl_opts);
|
||||
} else {
|
||||
$curlResult = DI::httpClient()->get($request, $curl_opts);
|
||||
$curlResult = DI::httpClient()->get($request, HttpClientAccept::JSON_AS, $curl_opts);
|
||||
}
|
||||
$return_code = $curlResult->getReturnCode();
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace Friendica\Util;
|
|||
use Friendica\Core\Logger;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Network\HTTPClient\Client\HttpClient;
|
||||
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
||||
|
||||
/**
|
||||
* Image utilities
|
||||
|
@ -220,7 +220,7 @@ class Images
|
|||
}
|
||||
|
||||
if (empty($img_str)) {
|
||||
$img_str = DI::httpClient()->fetch($url, 4, HttpClient::ACCEPT_IMAGE);
|
||||
$img_str = DI::httpClient()->fetch($url, HttpClientAccept::IMAGE, 4);
|
||||
}
|
||||
|
||||
if (!$img_str) {
|
||||
|
|
|
@ -29,7 +29,7 @@ use Friendica\Core\Logger;
|
|||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Network\HTTPClient\Client\HttpClient;
|
||||
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
||||
|
||||
|
@ -59,13 +59,13 @@ class ParseUrl
|
|||
* @param string $accept content-type to accept
|
||||
* @return array content type
|
||||
*/
|
||||
public static function getContentType(string $url, string $accept = HttpClient::ACCEPT_DEFAULT)
|
||||
public static function getContentType(string $url, string $accept = HttpClientAccept::DEFAULT)
|
||||
{
|
||||
$curlResult = DI::httpClient()->head($url, [HttpClientOptions::ACCEPT_CONTENT => $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 => HttpClient::ACCEPT_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