mirror of
https://github.com/wallabag/wallabag.git
synced 2024-06-12 10:19:29 +00:00
34 lines
809 B
PHP
34 lines
809 B
PHP
|
<?php
|
||
|
|
||
|
namespace Wallabag\CoreBundle\Guzzle;
|
||
|
|
||
|
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));
|
||
|
}
|
||
|
}
|