return $this->body;
}
+ /** {@inheritDoc} */
+ public function getInfo()
+ {
+ return $this->info;
+ }
+
/** {@inheritDoc} */
public function isRedirectUrl()
{
return $this->url;
}
+ public function getInfo()
+ {
+ // TODO: Implement getInfo() method.
+ }
+
/** {@inheritDoc} */
public function isRedirectUrl()
{
use Friendica\Util\Profiler;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
-use GuzzleHttp\Exception\TransferException;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;
$this->logger->notice('Curl redirect.', ['url' => $request->getUri(), 'to' => $uri]);
};
- $onHeaders = function (ResponseInterface $response) use ($opts) {
- if (!empty($opts['content_length']) &&
- $response->getHeaderLine('Content-Length') > $opts['content_length']) {
- throw new TransferException('The file is too big!');
- }
- };
-
$client = new Client([
'allow_redirect' => [
'max' => 8,
try {
$response = $client->get($url);
return new GuzzleResponse($response, $url);
- } catch (TransferException $exception) {
- if ($exception instanceof RequestException &&
- $exception->hasResponse()) {
+ } catch (RequestException $exception) {
+ if ($exception->hasResponse()) {
return new GuzzleResponse($exception->getResponse(), $url, $exception->getCode(), $exception->getMessage());
} else {
return new CurlResult($url, '', ['http_code' => $exception->getCode()], $exception->getCode(), $exception->getMessage());
* 'nobody' => only return the header
* 'cookiejar' => path to cookie jar file
* 'header' => header array
- * 'content_length' => int maximum File content length
*
* @return IHTTPResult
*/
*/
public function getBody();
+ /**
+ * @return array
+ */
+ public function getInfo();
+
/**
* @return boolean
*/
*/
private static function getHideStatus($url)
{
- $curlResult = DI::httpRequest()->get($url, false, ['content_length' => 1000000]);
+ $curlResult = DI::httpRequest()->get($url);
if (!$curlResult->isSuccess()) {
return false;
}
+ // If the file is too large then exit
+ if (($curlResult->getInfo()['download_content_length'] ?? 0) > 1000000) {
+ return false;
+ }
+
// If it isn't a HTML file then exit
if (($curlResult->getContentType() != '') && !strstr(strtolower($curlResult->getContentType()), 'html')) {
return false;
return $siteinfo;
}
- $curlResult = DI::httpRequest()->get($url, false, ['content_length' => 1000000]);
+ $curlResult = DI::httpRequest()->get($url);
if (!$curlResult->isSuccess()) {
return $siteinfo;
}
+ // If the file is too large then exit
+ if (($curlResult->getInfo()['download_content_length'] ?? 0) > 1000000) {
+ return $siteinfo;
+ }
+
// If it isn't a HTML file then exit
if (($curlResult->getContentType() != '') && !strstr(strtolower($curlResult->getContentType()), 'html')) {
return $siteinfo;