Revert "HTTPRequest: Replace getInfo() with new parameter 'content_length'"
This reverts commit f3cd973c
This commit is contained in:
parent
0449077126
commit
2e8ad098b9
|
@ -319,6 +319,12 @@ class CurlResult implements IHTTPResult
|
||||||
return $this->body;
|
return $this->body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
public function getInfo()
|
||||||
|
{
|
||||||
|
return $this->info;
|
||||||
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public function isRedirectUrl()
|
public function isRedirectUrl()
|
||||||
{
|
{
|
||||||
|
|
|
@ -121,6 +121,11 @@ class GuzzleResponse extends Response implements IHTTPResult, ResponseInterface
|
||||||
return $this->url;
|
return $this->url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getInfo()
|
||||||
|
{
|
||||||
|
// TODO: Implement getInfo() method.
|
||||||
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public function isRedirectUrl()
|
public function isRedirectUrl()
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,7 +30,6 @@ use Friendica\Util\Network;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\RequestException;
|
use GuzzleHttp\Exception\RequestException;
|
||||||
use GuzzleHttp\Exception\TransferException;
|
|
||||||
use Psr\Http\Message\RequestInterface;
|
use Psr\Http\Message\RequestInterface;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\UriInterface;
|
use Psr\Http\Message\UriInterface;
|
||||||
|
@ -187,13 +186,6 @@ class HTTPRequest implements IHTTPRequest
|
||||||
$this->logger->notice('Curl redirect.', ['url' => $request->getUri(), 'to' => $uri]);
|
$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([
|
$client = new Client([
|
||||||
'allow_redirect' => [
|
'allow_redirect' => [
|
||||||
'max' => 8,
|
'max' => 8,
|
||||||
|
@ -210,9 +202,8 @@ class HTTPRequest implements IHTTPRequest
|
||||||
try {
|
try {
|
||||||
$response = $client->get($url);
|
$response = $client->get($url);
|
||||||
return new GuzzleResponse($response, $url);
|
return new GuzzleResponse($response, $url);
|
||||||
} catch (TransferException $exception) {
|
} catch (RequestException $exception) {
|
||||||
if ($exception instanceof RequestException &&
|
if ($exception->hasResponse()) {
|
||||||
$exception->hasResponse()) {
|
|
||||||
return new GuzzleResponse($exception->getResponse(), $url, $exception->getCode(), $exception->getMessage());
|
return new GuzzleResponse($exception->getResponse(), $url, $exception->getCode(), $exception->getMessage());
|
||||||
} else {
|
} else {
|
||||||
return new CurlResult($url, '', ['http_code' => $exception->getCode()], $exception->getCode(), $exception->getMessage());
|
return new CurlResult($url, '', ['http_code' => $exception->getCode()], $exception->getCode(), $exception->getMessage());
|
||||||
|
|
|
@ -75,7 +75,6 @@ interface IHTTPRequest
|
||||||
* 'nobody' => only return the header
|
* 'nobody' => only return the header
|
||||||
* 'cookiejar' => path to cookie jar file
|
* 'cookiejar' => path to cookie jar file
|
||||||
* 'header' => header array
|
* 'header' => header array
|
||||||
* 'content_length' => int maximum File content length
|
|
||||||
*
|
*
|
||||||
* @return IHTTPResult
|
* @return IHTTPResult
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -82,6 +82,11 @@ interface IHTTPResult
|
||||||
*/
|
*/
|
||||||
public function getBody();
|
public function getBody();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getInfo();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -423,11 +423,16 @@ class Probe
|
||||||
*/
|
*/
|
||||||
private static function getHideStatus($url)
|
private static function getHideStatus($url)
|
||||||
{
|
{
|
||||||
$curlResult = DI::httpRequest()->get($url, false, ['content_length' => 1000000]);
|
$curlResult = DI::httpRequest()->get($url);
|
||||||
if (!$curlResult->isSuccess()) {
|
if (!$curlResult->isSuccess()) {
|
||||||
return false;
|
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 it isn't a HTML file then exit
|
||||||
if (($curlResult->getContentType() != '') && !strstr(strtolower($curlResult->getContentType()), 'html')) {
|
if (($curlResult->getContentType() != '') && !strstr(strtolower($curlResult->getContentType()), 'html')) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -160,11 +160,16 @@ class ParseUrl
|
||||||
return $siteinfo;
|
return $siteinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
$curlResult = DI::httpRequest()->get($url, false, ['content_length' => 1000000]);
|
$curlResult = DI::httpRequest()->get($url);
|
||||||
if (!$curlResult->isSuccess()) {
|
if (!$curlResult->isSuccess()) {
|
||||||
return $siteinfo;
|
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 it isn't a HTML file then exit
|
||||||
if (($curlResult->getContentType() != '') && !strstr(strtolower($curlResult->getContentType()), 'html')) {
|
if (($curlResult->getContentType() != '') && !strstr(strtolower($curlResult->getContentType()), 'html')) {
|
||||||
return $siteinfo;
|
return $siteinfo;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user