mirror of
https://github.com/friendica/friendica
synced 2025-05-01 09:04:24 +02:00
Some more "accept" parameters are added
This commit is contained in:
parent
173e72169b
commit
1fae0123ec
32 changed files with 111 additions and 60 deletions
|
@ -29,6 +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\HTTPException;
|
||||
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
||||
|
||||
|
@ -54,16 +55,17 @@ class ParseUrl
|
|||
|
||||
/**
|
||||
* Fetch the content type of the given url
|
||||
* @param string $url URL of the page
|
||||
* @param string $url URL of the page
|
||||
* @param string $accept content-type to accept
|
||||
* @return array content type
|
||||
*/
|
||||
public static function getContentType(string $url)
|
||||
public static function getContentType(string $url, string $accept = HttpClient::ACCEPT_DEFAULT)
|
||||
{
|
||||
$curlResult = DI::httpClient()->head($url);
|
||||
$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]);
|
||||
$curlResult = DI::httpClient()->get($url, [HttpClientOptions::CONTENT_LENGTH => 1000000, HttpClientOptions::ACCEPT_CONTENT => $accept]);
|
||||
}
|
||||
|
||||
if (!$curlResult->isSuccess()) {
|
||||
|
@ -220,7 +222,7 @@ class ParseUrl
|
|||
return $siteinfo;
|
||||
}
|
||||
|
||||
$curlResult = DI::httpClient()->get($url, [HttpClientOptions::CONTENT_LENGTH => 1000000]);
|
||||
$curlResult = DI::httpClient()->get($url, [HttpClientOptions::CONTENT_LENGTH => 1000000, HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_HTML]);
|
||||
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