From bf9ace0643f654e7ccd9c020b8b501ad56cd19de Mon Sep 17 00:00:00 2001 From: adev Date: Tue, 24 Oct 2017 22:55:40 +0200 Subject: Use httplug --- .../CoreBundle/Helper/HttpClientFactory.php | 47 ++++++++++++---------- 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'src/Wallabag/CoreBundle/Helper/HttpClientFactory.php') diff --git a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php index 4602a684..4899d3d4 100644 --- a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php +++ b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php @@ -2,16 +2,18 @@ namespace Wallabag\CoreBundle\Helper; -use Graby\Ring\Client\SafeCurlHandler; -use GuzzleHttp\Client; +use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\Cookie\CookieJar; use GuzzleHttp\Event\SubscriberInterface; +use Http\Adapter\Guzzle5\Client as GuzzleAdapter; use Psr\Log\LoggerInterface; +use Http\Client\HttpClient; +use Http\HttplugBundle\ClientFactory\ClientFactory; /** - * Builds and configures the Guzzle HTTP client. + * Builds and configures the HTTP client. */ -class HttpClientFactory +class HttpClientFactory implements ClientFactory { /** @var [\GuzzleHttp\Event\SubscriberInterface] */ private $subscribers = []; @@ -37,35 +39,38 @@ class HttpClientFactory } /** - * @return \GuzzleHttp\Client|null + * Adds a subscriber to the HTTP client. + * + * @param SubscriberInterface $subscriber + */ + public function addSubscriber(SubscriberInterface $subscriber) + { + $this->subscribers[] = $subscriber; + } + + /** + * Input an array of configuration to be able to create a HttpClient. + * + * @param array $config + * + * @return HttpClient */ - public function buildHttpClient() + public function createClient(array $config = []) { $this->logger->log('debug', 'Restricted access config enabled?', ['enabled' => (int) $this->restrictedAccess]); if (0 === (int) $this->restrictedAccess) { - return; + return new GuzzleAdapter(new GuzzleClient()); } // we clear the cookie to avoid websites who use cookies for analytics $this->cookieJar->clear(); // need to set the (shared) cookie jar - $client = new Client(['handler' => new SafeCurlHandler(), 'defaults' => ['cookies' => $this->cookieJar]]); - + $guzzle = new GuzzleClient(['defaults' => ['cookies' => $this->cookieJar]]); foreach ($this->subscribers as $subscriber) { - $client->getEmitter()->attach($subscriber); + $guzzle->getEmitter()->attach($subscriber); } - return $client; - } - - /** - * Adds a subscriber to the HTTP client. - * - * @param SubscriberInterface $subscriber - */ - public function addSubscriber(SubscriberInterface $subscriber) - { - $this->subscribers[] = $subscriber; + return new GuzzleAdapter($guzzle); } } -- cgit v1.2.3 From 1048c9c4a811821b00cc04bfec905bebcc22bac4 Mon Sep 17 00:00:00 2001 From: adev Date: Sun, 12 Nov 2017 12:15:02 +0100 Subject: Configure timeout --- src/Wallabag/CoreBundle/Helper/HttpClientFactory.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/CoreBundle/Helper/HttpClientFactory.php') diff --git a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php index 4899d3d4..3e19a7be 100644 --- a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php +++ b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php @@ -60,13 +60,17 @@ class HttpClientFactory implements ClientFactory $this->logger->log('debug', 'Restricted access config enabled?', ['enabled' => (int) $this->restrictedAccess]); if (0 === (int) $this->restrictedAccess) { - return new GuzzleAdapter(new GuzzleClient()); + return new GuzzleAdapter(new GuzzleClient($config)); } // we clear the cookie to avoid websites who use cookies for analytics $this->cookieJar->clear(); - // need to set the (shared) cookie jar - $guzzle = new GuzzleClient(['defaults' => ['cookies' => $this->cookieJar]]); + if (!isset($config['defaults']['cookies'])) { + // need to set the (shared) cookie jar + $config['defaults']['cookies'] = $this->cookieJar; + } + + $guzzle = new GuzzleClient($config); foreach ($this->subscribers as $subscriber) { $guzzle->getEmitter()->attach($subscriber); } -- cgit v1.2.3 From 448d99f84e93697ce49ec31224addb1da1a37a9f Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 28 Jan 2019 06:10:26 +0100 Subject: CS --- src/Wallabag/CoreBundle/Helper/HttpClientFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Helper/HttpClientFactory.php') diff --git a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php index 3e19a7be..b8e95381 100644 --- a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php +++ b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php @@ -6,9 +6,9 @@ use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\Cookie\CookieJar; use GuzzleHttp\Event\SubscriberInterface; use Http\Adapter\Guzzle5\Client as GuzzleAdapter; -use Psr\Log\LoggerInterface; use Http\Client\HttpClient; use Http\HttplugBundle\ClientFactory\ClientFactory; +use Psr\Log\LoggerInterface; /** * Builds and configures the HTTP client. -- cgit v1.2.3 From 8d4ed0df0633f43fc2d65fef72c36070113844d1 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 12 Nov 2019 14:18:58 +0100 Subject: Update deps Also CS (because cs-fixer got an update) Package operations: 0 installs, 26 updates, 0 removals - Updating twig/twig (v2.12.1 => v2.12.2) - Updating symfony/symfony (v3.4.33 => v3.4.34) - Updating doctrine/event-manager (v1.0.0 => 1.1.0) - Updating doctrine/collections (v1.6.2 => 1.6.3) - Updating doctrine/cache (v1.8.1 => 1.9.0) - Updating doctrine/persistence (1.1.1 => 1.2.0) - Updating doctrine/inflector (v1.3.0 => 1.3.1) - Updating symfony/mime (v4.3.5 => v4.3.7) - Updating swiftmailer/swiftmailer (v6.2.1 => v6.2.3) - Updating symfony/swiftmailer-bundle (v3.3.0 => v3.3.1) - Updating doctrine/dbal (v2.9.2 => v2.9.3) - Updating doctrine/instantiator (1.2.0 => 1.3.0) - Updating j0k3r/graby-site-config (1.0.93 => 1.0.94) - Updating phpoption/phpoption (1.5.0 => 1.5.2) - Updating symfony/http-client-contracts (v1.1.7 => v1.1.8) - Updating symfony/http-client (v4.3.5 => v4.3.7) - Updating sensiolabs/security-checker (v6.0.2 => v6.0.3) - Updating paragonie/constant_time_encoding (v2.2.3 => v2.3.0) - Updating scheb/two-factor-bundle (v4.7.1 => v4.8.0) - Updating symfony/phpunit-bridge (v4.3.6 => v4.3.7) - Updating composer/xdebug-handler (1.3.3 => 1.4.0) - Updating friendsofphp/php-cs-fixer (v2.15.3 => v2.16.0) - Updating doctrine/data-fixtures (v1.3.2 => 1.3.3) - Updating nette/schema (v1.0.0 => v1.0.1) - Updating nikic/php-parser (v4.2.4 => v4.3.0) - Updating sentry/sentry (2.2.2 => 2.2.4) --- src/Wallabag/CoreBundle/Helper/HttpClientFactory.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'src/Wallabag/CoreBundle/Helper/HttpClientFactory.php') diff --git a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php index b8e95381..ea864acb 100644 --- a/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php +++ b/src/Wallabag/CoreBundle/Helper/HttpClientFactory.php @@ -27,9 +27,7 @@ class HttpClientFactory implements ClientFactory /** * HttpClientFactory constructor. * - * @param \GuzzleHttp\Cookie\CookieJar $cookieJar - * @param string $restrictedAccess This param is a kind of boolean. Values: 0 or 1 - * @param LoggerInterface $logger + * @param string $restrictedAccess This param is a kind of boolean. Values: 0 or 1 */ public function __construct(CookieJar $cookieJar, $restrictedAccess, LoggerInterface $logger) { @@ -40,8 +38,6 @@ class HttpClientFactory implements ClientFactory /** * Adds a subscriber to the HTTP client. - * - * @param SubscriberInterface $subscriber */ public function addSubscriber(SubscriberInterface $subscriber) { @@ -51,8 +47,6 @@ class HttpClientFactory implements ClientFactory /** * Input an array of configuration to be able to create a HttpClient. * - * @param array $config - * * @return HttpClient */ public function createClient(array $config = []) -- cgit v1.2.3