Skip to content

Commit daa809a

Browse files
authored
Merge pull request #319 from php-http/seekable-body-plugins
configure seekable body plugin
2 parents ddbd6dc + 2126f7e commit daa809a

File tree

5 files changed

+64
-3
lines changed

5 files changed

+64
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
44

55
# 1.28.0 - 2023-05-12
66

7-
- Added PHP 8.2 support
8-
- Allow installation with PSR-7 `psr/http-message` 2.x
7+
- Added: Configure the seekable body plugins.
8+
- Added: PHP 8.2 support.
9+
- Added: Allow installation with PSR-7 `psr/http-message` 2.x.
10+
- Added: alias to autowire `Psr\Http\Client\ClientInterface` service (#425).
911
- Deprecated `Http\Client\HttpClient` in favor of `Psr\Http\Client\ClientInterface` (#425).
10-
- Added alias to autowire `Psr\Http\Client\ClientInterface` service (#425).
1112

1213
# 1.27.1 - 2023-03-03
1314

src/DependencyInjection/Configuration.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,33 @@ private function createClientPluginNode()
444444
->end()
445445
->end()
446446
->end()
447+
->arrayNode('request_seekable_body')
448+
->canBeEnabled()
449+
->info('Ensure that the request body is seekable so that several plugins can look into it.')
450+
->children()
451+
->booleanNode('use_file_buffer')
452+
->info('Whether to use a file buffer if the stream is too big for a memory buffer')
453+
->defaultTrue()
454+
->end()
455+
->scalarNode('memory_buffer_size')
456+
->info('Maximum memory size in bytes before using a file buffer if use_file_buffer is true. Defaults to 2097152 (2 MB)')
457+
->end()
458+
->end()
459+
->end()
460+
->arrayNode('response_seekable_body')
461+
->canBeEnabled()
462+
->info('Ensure that the response body is seekable so that several plugins can look into it.')
463+
->children()
464+
->booleanNode('use_file_buffer')
465+
->info('Whether to use a file buffer if the stream is too big for a memory buffer')
466+
->defaultTrue()
467+
->end()
468+
->scalarNode('memory_buffer_size')
469+
->info('Maximum memory size in bytes before using a file buffer if use_file_buffer is true. Defaults to 2097152 (2 MB)')
470+
->end()
471+
->end()
472+
->end()
473+
447474
->arrayNode('vcr')
448475
->canBeEnabled()
449476
->addDefaultsIfNotSet()

src/DependencyInjection/HttplugExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ private function configurePluginByName($name, Definition $definition, array $con
341341

342342
break;
343343

344+
case 'request_seekable_body':
345+
case 'response_seekable_body':
346+
$definition->replaceArgument(0, $config);
347+
break;
348+
344349
default:
345350
throw new \InvalidArgumentException(sprintf('Internal exception: Plugin %s is not handled', $name));
346351
}

src/Resources/config/plugins.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@
6060
<service id="httplug.plugin.query_defaults" class="Http\Client\Common\Plugin\QueryDefaultsPlugin" public="false" abstract="true">
6161
<argument/>
6262
</service>
63+
<service id="httplug.plugin.request_seekable_body" class="Http\Client\Common\Plugin\RequestSeekableBodyPlugin" public="false" abstract="true">
64+
<argument/>
65+
</service>
66+
<service id="httplug.plugin.response_seekable_body" class="Http\Client\Common\Plugin\ResponseSeekableBodyPlugin" public="false" abstract="true">
67+
<argument/>
68+
</service>
6369

6470
</services>
6571
</container>

tests/Unit/DependencyInjection/HttplugExtensionTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ public function testClientPlugins(): void
9595
'host' => 'http://localhost:8000',
9696
],
9797
],
98+
[
99+
'add_path' => [
100+
'path' => '/v1',
101+
],
102+
],
103+
[
104+
'base_uri' => [
105+
'uri' => 'https://localhost:8000/v1',
106+
],
107+
],
98108
[
99109
'content_type' => [
100110
'skip_detection' => true,
@@ -120,6 +130,14 @@ public function testClientPlugins(): void
120130
'headers' => ['X-FOO'],
121131
],
122132
],
133+
[
134+
'request_seekable_body' => [
135+
'use_file_buffer' => true,
136+
],
137+
],
138+
[
139+
'response_seekable_body' => true,
140+
],
123141
[
124142
'query_defaults' => [
125143
'parameters' => ['locale' => 'en'],
@@ -153,11 +171,15 @@ public function testClientPlugins(): void
153171
'httplug.client.acme.plugin.decoder',
154172
'httplug.plugin.redirect',
155173
'httplug.client.acme.plugin.add_host',
174+
'httplug.client.acme.plugin.add_path',
175+
'httplug.client.acme.plugin.base_uri',
156176
'httplug.client.acme.plugin.content_type',
157177
'httplug.client.acme.plugin.header_append',
158178
'httplug.client.acme.plugin.header_defaults',
159179
'httplug.client.acme.plugin.header_set',
160180
'httplug.client.acme.plugin.header_remove',
181+
'httplug.client.acme.plugin.request_seekable_body',
182+
'httplug.client.acme.plugin.response_seekable_body',
161183
'httplug.client.acme.plugin.query_defaults',
162184
'httplug.client.acme.authentication.my_basic',
163185
'httplug.client.acme.plugin.cache',

0 commit comments

Comments
 (0)