From 4722773222b88118f8680137dc8d1ae25bd2aa31 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 5 Mar 2019 08:34:41 +0100 Subject: [PATCH 1/2] WIP configure seekable body plugin --- src/DependencyInjection/Configuration.php | 26 +++++++++++++++++++ src/DependencyInjection/HttplugExtension.php | 5 ++++ .../HttplugExtensionTest.php | 6 +++++ 3 files changed, 37 insertions(+) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 74c612a6..d357f36f 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -488,6 +488,32 @@ private function createClientPluginNode() ->info('Where the responses will be stored and replay from when using the filesystem recorder. Should be accessible to your VCS.') ->end() ->end() + ->arrayNode('request_seekable_body') + ->canBeEnabled() + ->info('Ensure that the request body is seekable so that several plugins can look into it.') + ->children() + ->booleanNode('use_file_buffer') + ->info('Whether to use a file buffer if the stream is too big for a memory buffer') + ->defaultTrue() + ->end() + ->scalarNode('memory_buffer_size') + ->info('Maximum memory size in bytes before using a file buffer if use_file_buffer is true. Defaults to 2 MB') + ->end() + ->end() + ->end() + ->arrayNode('response_seekable_body') + ->canBeEnabled() + ->info('Ensure that the response body is seekable so that several plugins can look into it.') + ->children() + ->booleanNode('use_file_buffer') + ->info('Whether to use a file buffer if the stream is too big for a memory buffer') + ->defaultTrue() + ->end() + ->scalarNode('memory_buffer_size') + ->info('Maximum memory size in bytes before using a file buffer if use_file_buffer is true. Defaults to 2 MB') + ->end() + ->end() + ->end() ->end() ->end(); diff --git a/src/DependencyInjection/HttplugExtension.php b/src/DependencyInjection/HttplugExtension.php index 4b9e2668..db2a3a3b 100644 --- a/src/DependencyInjection/HttplugExtension.php +++ b/src/DependencyInjection/HttplugExtension.php @@ -341,6 +341,11 @@ private function configurePluginByName($name, Definition $definition, array $con break; + case 'request_seekable_body': + case 'response_seekable_body': + $definition->replaceArgument(0, $config); + break; + default: throw new \InvalidArgumentException(sprintf('Internal exception: Plugin %s is not handled', $name)); } diff --git a/tests/Unit/DependencyInjection/HttplugExtensionTest.php b/tests/Unit/DependencyInjection/HttplugExtensionTest.php index 405f2bdc..64e52869 100644 --- a/tests/Unit/DependencyInjection/HttplugExtensionTest.php +++ b/tests/Unit/DependencyInjection/HttplugExtensionTest.php @@ -120,6 +120,12 @@ public function testClientPlugins(): void 'headers' => ['X-FOO'], ], ], + [ + 'request_seekable_body' => [ + 'use_file_buffer' => true, + ], + ], +// 'response_seekable_body', [ 'query_defaults' => [ 'parameters' => ['locale' => 'en'], From 2126f7e28f84a861144ed1b3a44fd0c15dcd8478 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 12 May 2023 10:47:55 +0200 Subject: [PATCH 2/2] seekable body plugin --- CHANGELOG.md | 7 +-- src/DependencyInjection/Configuration.php | 53 ++++++++++--------- src/Resources/config/plugins.xml | 6 +++ .../HttplugExtensionTest.php | 18 ++++++- 4 files changed, 54 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a462ab5..478c93f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,11 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee # 1.28.0 - 2023-05-12 -- Added PHP 8.2 support -- Allow installation with PSR-7 `psr/http-message` 2.x +- Added: Configure the seekable body plugins. +- Added: PHP 8.2 support. +- Added: Allow installation with PSR-7 `psr/http-message` 2.x. +- Added: alias to autowire `Psr\Http\Client\ClientInterface` service (#425). - Deprecated `Http\Client\HttpClient` in favor of `Psr\Http\Client\ClientInterface` (#425). -- Added alias to autowire `Psr\Http\Client\ClientInterface` service (#425). # 1.27.1 - 2023-03-03 diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index d357f36f..792ced49 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -444,6 +444,33 @@ private function createClientPluginNode() ->end() ->end() ->end() + ->arrayNode('request_seekable_body') + ->canBeEnabled() + ->info('Ensure that the request body is seekable so that several plugins can look into it.') + ->children() + ->booleanNode('use_file_buffer') + ->info('Whether to use a file buffer if the stream is too big for a memory buffer') + ->defaultTrue() + ->end() + ->scalarNode('memory_buffer_size') + ->info('Maximum memory size in bytes before using a file buffer if use_file_buffer is true. Defaults to 2097152 (2 MB)') + ->end() + ->end() + ->end() + ->arrayNode('response_seekable_body') + ->canBeEnabled() + ->info('Ensure that the response body is seekable so that several plugins can look into it.') + ->children() + ->booleanNode('use_file_buffer') + ->info('Whether to use a file buffer if the stream is too big for a memory buffer') + ->defaultTrue() + ->end() + ->scalarNode('memory_buffer_size') + ->info('Maximum memory size in bytes before using a file buffer if use_file_buffer is true. Defaults to 2097152 (2 MB)') + ->end() + ->end() + ->end() + ->arrayNode('vcr') ->canBeEnabled() ->addDefaultsIfNotSet() @@ -488,32 +515,6 @@ private function createClientPluginNode() ->info('Where the responses will be stored and replay from when using the filesystem recorder. Should be accessible to your VCS.') ->end() ->end() - ->arrayNode('request_seekable_body') - ->canBeEnabled() - ->info('Ensure that the request body is seekable so that several plugins can look into it.') - ->children() - ->booleanNode('use_file_buffer') - ->info('Whether to use a file buffer if the stream is too big for a memory buffer') - ->defaultTrue() - ->end() - ->scalarNode('memory_buffer_size') - ->info('Maximum memory size in bytes before using a file buffer if use_file_buffer is true. Defaults to 2 MB') - ->end() - ->end() - ->end() - ->arrayNode('response_seekable_body') - ->canBeEnabled() - ->info('Ensure that the response body is seekable so that several plugins can look into it.') - ->children() - ->booleanNode('use_file_buffer') - ->info('Whether to use a file buffer if the stream is too big for a memory buffer') - ->defaultTrue() - ->end() - ->scalarNode('memory_buffer_size') - ->info('Maximum memory size in bytes before using a file buffer if use_file_buffer is true. Defaults to 2 MB') - ->end() - ->end() - ->end() ->end() ->end(); diff --git a/src/Resources/config/plugins.xml b/src/Resources/config/plugins.xml index 136869b6..749407c4 100644 --- a/src/Resources/config/plugins.xml +++ b/src/Resources/config/plugins.xml @@ -60,6 +60,12 @@ + + + + + + diff --git a/tests/Unit/DependencyInjection/HttplugExtensionTest.php b/tests/Unit/DependencyInjection/HttplugExtensionTest.php index 64e52869..3b65c540 100644 --- a/tests/Unit/DependencyInjection/HttplugExtensionTest.php +++ b/tests/Unit/DependencyInjection/HttplugExtensionTest.php @@ -95,6 +95,16 @@ public function testClientPlugins(): void 'host' => 'http://localhost:8000', ], ], + [ + 'add_path' => [ + 'path' => '/v1', + ], + ], + [ + 'base_uri' => [ + 'uri' => 'https://localhost:8000/v1', + ], + ], [ 'content_type' => [ 'skip_detection' => true, @@ -125,7 +135,9 @@ public function testClientPlugins(): void 'use_file_buffer' => true, ], ], -// 'response_seekable_body', + [ + 'response_seekable_body' => true, + ], [ 'query_defaults' => [ 'parameters' => ['locale' => 'en'], @@ -159,11 +171,15 @@ public function testClientPlugins(): void 'httplug.client.acme.plugin.decoder', 'httplug.plugin.redirect', 'httplug.client.acme.plugin.add_host', + 'httplug.client.acme.plugin.add_path', + 'httplug.client.acme.plugin.base_uri', 'httplug.client.acme.plugin.content_type', 'httplug.client.acme.plugin.header_append', 'httplug.client.acme.plugin.header_defaults', 'httplug.client.acme.plugin.header_set', 'httplug.client.acme.plugin.header_remove', + 'httplug.client.acme.plugin.request_seekable_body', + 'httplug.client.acme.plugin.response_seekable_body', 'httplug.client.acme.plugin.query_defaults', 'httplug.client.acme.authentication.my_basic', 'httplug.client.acme.plugin.cache',