2024-02-02 20:56:25 +00:00
|
|
|
<?php
|
|
|
|
|
2024-02-19 00:30:12 +00:00
|
|
|
namespace Wallabag\Guzzle;
|
2024-02-02 20:56:25 +00:00
|
|
|
|
|
|
|
use GuzzleHttp\Event\CompleteEvent;
|
|
|
|
use GuzzleHttp\Event\SubscriberInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fixes url encoding of a parameter guzzle fails with.
|
|
|
|
*/
|
|
|
|
class FixupMondeDiplomatiqueUriSubscriber implements SubscriberInterface
|
|
|
|
{
|
|
|
|
public function getEvents(): array
|
|
|
|
{
|
|
|
|
return ['complete' => [['fixUri', 500]]];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function fixUri(CompleteEvent $event)
|
|
|
|
{
|
|
|
|
$response = $event->getResponse();
|
|
|
|
|
|
|
|
if (!$response->hasHeader('Location')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$uri = $response->getHeader('Location');
|
|
|
|
if (false === ($badParameter = strstr($uri, 'retour=http://'))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$response->setHeader('Location', str_replace($badParameter, urlencode($badParameter), $uri));
|
|
|
|
}
|
|
|
|
}
|