Skip to content

configure seekable body plugin #319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 27 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions src/DependencyInjection/HttplugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
6 changes: 6 additions & 0 deletions src/Resources/config/plugins.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
<service id="httplug.plugin.query_defaults" class="Http\Client\Common\Plugin\QueryDefaultsPlugin" public="false" abstract="true">
<argument/>
</service>
<service id="httplug.plugin.request_seekable_body" class="Http\Client\Common\Plugin\RequestSeekableBodyPlugin" public="false" abstract="true">
<argument/>
</service>
<service id="httplug.plugin.response_seekable_body" class="Http\Client\Common\Plugin\ResponseSeekableBodyPlugin" public="false" abstract="true">
<argument/>
</service>

</services>
</container>
22 changes: 22 additions & 0 deletions tests/Unit/DependencyInjection/HttplugExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'],
Expand Down Expand Up @@ -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',
Expand Down