use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Network\HTTPException;
+use Friendica\Network\HTTPClientOptions;
/**
* Get information about a given URL
*/
public static function getContentType(string $url)
{
- $curlResult = DI::httpRequest()->head($url);
+ $curlResult = DI::httpClient()->head($url);
if (!$curlResult->isSuccess()) {
return [];
}
- $contenttype = $curlResult->getHeader('Content-Type');
+ $contenttype = $curlResult->getHeader('Content-Type')[0] ?? '';
if (empty($contenttype)) {
return [];
}
return $siteinfo;
}
- $curlResult = DI::httpRequest()->get($url, false, ['content_length' => 1000000]);
+ $curlResult = DI::httpClient()->get($url, [HTTPClientOptions::CONTENT_LENGTH => 1000000]);
if (!$curlResult->isSuccess() || empty($curlResult->getBody())) {
return $siteinfo;
}
$siteinfo['expires'] = DateTimeFormat::utc(self::DEFAULT_EXPIRATION_SUCCESS);
- // If the file is too large then exit
- if (($curlResult->getInfo()['download_content_length'] ?? 0) > 1000000) {
- return $siteinfo;
- }
-
- if ($cacheControlHeader = $curlResult->getHeader('Cache-Control')) {
+ if ($cacheControlHeader = $curlResult->getHeader('Cache-Control')[0] ?? '') {
if (preg_match('/max-age=([0-9]+)/i', $cacheControlHeader, $matches)) {
$maxAge = max(86400, (int)array_pop($matches));
$siteinfo['expires'] = DateTimeFormat::utc("now + $maxAge seconds");
$charset = '';
// Look for a charset, first in headers
// Expected form: Content-Type: text/html; charset=ISO-8859-4
- foreach ($curlResult->getContentType() as $type) {
- if (preg_match('/charset=([a-z0-9-_.\/]+)/i', $type, $matches)) {
- $charset = trim(trim(trim(array_pop($matches)), ';,'));
- }
+ if (preg_match('/charset=([a-z0-9-_.\/]+)/i', $curlResult->getContentType(), $matches)) {
+ $charset = trim(trim(trim(array_pop($matches)), ';,'));
}
// Then in body that gets precedence