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 74c612a6..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() 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/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 405f2bdc..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, @@ -120,6 +130,14 @@ public function testClientPlugins(): void 'headers' => ['X-FOO'], ], ], + [ + 'request_seekable_body' => [ + 'use_file_buffer' => true, + ], + ], + [ + 'response_seekable_body' => true, + ], [ 'query_defaults' => [ 'parameters' => ['locale' => 'en'], @@ -153,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',