Skip to content

Commit f6a20e8

Browse files
committed
seekable body plugin
1 parent 4722773 commit f6a20e8

File tree

3 files changed

+51
-27
lines changed

3 files changed

+51
-27
lines changed

src/DependencyInjection/Configuration.php

+28-26
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 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 2 MB')
470+
->end()
471+
->end()
472+
->end()
473+
447474
->arrayNode('vcr')
448475
->canBeEnabled()
449476
->addDefaultsIfNotSet()
@@ -488,32 +515,7 @@ private function createClientPluginNode()
488515
->info('Where the responses will be stored and replay from when using the filesystem recorder. Should be accessible to your VCS.')
489516
->end()
490517
->end()
491-
->arrayNode('request_seekable_body')
492-
->canBeEnabled()
493-
->info('Ensure that the request body is seekable so that several plugins can look into it.')
494-
->children()
495-
->booleanNode('use_file_buffer')
496-
->info('Whether to use a file buffer if the stream is too big for a memory buffer')
497-
->defaultTrue()
498-
->end()
499-
->scalarNode('memory_buffer_size')
500-
->info('Maximum memory size in bytes before using a file buffer if use_file_buffer is true. Defaults to 2 MB')
501-
->end()
502-
->end()
503-
->end()
504-
->arrayNode('response_seekable_body')
505-
->canBeEnabled()
506-
->info('Ensure that the response body is seekable so that several plugins can look into it.')
507-
->children()
508-
->booleanNode('use_file_buffer')
509-
->info('Whether to use a file buffer if the stream is too big for a memory buffer')
510-
->defaultTrue()
511-
->end()
512-
->scalarNode('memory_buffer_size')
513-
->info('Maximum memory size in bytes before using a file buffer if use_file_buffer is true. Defaults to 2 MB')
514-
->end()
515-
->end()
516-
->end()
518+
->end()
517519
->end()
518520
->end();
519521

src/Resources/config/plugins.xml

+6
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

+17-1
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,
@@ -125,7 +135,9 @@ public function testClientPlugins(): void
125135
'use_file_buffer' => true,
126136
],
127137
],
128-
// 'response_seekable_body',
138+
[
139+
'response_seekable_body' => true,
140+
],
129141
[
130142
'query_defaults' => [
131143
'parameters' => ['locale' => 'en'],
@@ -159,11 +171,15 @@ public function testClientPlugins(): void
159171
'httplug.client.acme.plugin.decoder',
160172
'httplug.plugin.redirect',
161173
'httplug.client.acme.plugin.add_host',
174+
'httplug.client.acme.plugin.add_path',
175+
'httplug.client.acme.plugin.base_uri',
162176
'httplug.client.acme.plugin.content_type',
163177
'httplug.client.acme.plugin.header_append',
164178
'httplug.client.acme.plugin.header_defaults',
165179
'httplug.client.acme.plugin.header_set',
166180
'httplug.client.acme.plugin.header_remove',
181+
'httplug.client.acme.plugin.request_seekable_body',
182+
'httplug.client.acme.plugin.response_seekable_body',
167183
'httplug.client.acme.plugin.query_defaults',
168184
'httplug.client.acme.authentication.my_basic',
169185
'httplug.client.acme.plugin.cache',

0 commit comments

Comments
 (0)