Merge pull request #6562 from Simounet/fix/downloadimages-redirect-following
Fix DownloadImages not following redirections
This commit is contained in:
commit
bea10aacbe
@ -7,6 +7,7 @@ use GuzzleHttp\Psr7\Uri;
|
|||||||
use GuzzleHttp\Psr7\UriResolver;
|
use GuzzleHttp\Psr7\UriResolver;
|
||||||
use Http\Client\Common\HttpMethodsClient;
|
use Http\Client\Common\HttpMethodsClient;
|
||||||
use Http\Client\Common\Plugin\ErrorPlugin;
|
use Http\Client\Common\Plugin\ErrorPlugin;
|
||||||
|
use Http\Client\Common\Plugin\RedirectPlugin;
|
||||||
use Http\Client\Common\PluginClient;
|
use Http\Client\Common\PluginClient;
|
||||||
use Http\Client\HttpClient;
|
use Http\Client\HttpClient;
|
||||||
use Http\Discovery\MessageFactoryDiscovery;
|
use Http\Discovery\MessageFactoryDiscovery;
|
||||||
@ -29,7 +30,7 @@ class DownloadImages
|
|||||||
|
|
||||||
public function __construct(HttpClient $client, $baseFolder, $wallabagUrl, LoggerInterface $logger, MessageFactory $messageFactory = null)
|
public function __construct(HttpClient $client, $baseFolder, $wallabagUrl, LoggerInterface $logger, MessageFactory $messageFactory = null)
|
||||||
{
|
{
|
||||||
$this->client = new HttpMethodsClient(new PluginClient($client, [new ErrorPlugin()]), $messageFactory ?: MessageFactoryDiscovery::find());
|
$this->client = new HttpMethodsClient(new PluginClient($client, [new ErrorPlugin(), new RedirectPlugin()]), $messageFactory ?: MessageFactoryDiscovery::find());
|
||||||
$this->baseFolder = $baseFolder;
|
$this->baseFolder = $baseFolder;
|
||||||
$this->wallabagUrl = rtrim($wallabagUrl, '/');
|
$this->wallabagUrl = rtrim($wallabagUrl, '/');
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
|
@ -265,4 +265,19 @@ class DownloadImagesTest extends TestCase
|
|||||||
|
|
||||||
$this->assertFalse($res);
|
$this->assertFalse($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFollowRedirection()
|
||||||
|
{
|
||||||
|
$httpMockClient = new HttpMockClient();
|
||||||
|
$httpMockClient->addResponse(new Response(301, ['content-type' => 'image/png', 'location' => '/final-path.png']));
|
||||||
|
$httpMockClient->addResponse(new Response(200, ['content-type' => 'image/png'], file_get_contents(__DIR__ . '/../fixtures/unnamed.png')));
|
||||||
|
|
||||||
|
$logHandler = new TestHandler();
|
||||||
|
$logger = new Logger('test', [$logHandler]);
|
||||||
|
|
||||||
|
$download = new DownloadImages($httpMockClient, sys_get_temp_dir() . '/wallabag_test', 'http://wallabag.io/', $logger);
|
||||||
|
$res = $download->processSingleImage(123, '', 'https://example.com/unnamed.png');
|
||||||
|
|
||||||
|
$this->assertStringContainsString('/assets/images/9/b/9b0ead26/66953334.png', $res, "Fetch client didn't follow the HTTP redirection");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user