Skip to content

Commit 6a74d86

Browse files
jdecooldbu
authored andcommitted
Allow to disable body limitation size (#322)
1 parent d053921 commit 6a74d86

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
1717
- Removed `twig/twig` dependency
1818
- Removed hard dependency on `php-http/cache-plugin`. If you want to use the
1919
cache plugin, you need to require it in your project.
20+
- Allow to set `httpplug.profiling.captured_body_length` configuration to `null`
21+
to avoid body limitation size.
2022

2123
### Fixed
2224

src/DependencyInjection/Configuration.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,25 @@ public function getConfigTreeBuilder()
140140
->defaultValue($this->debug)
141141
->end()
142142
->scalarNode('formatter')->defaultNull()->end()
143-
->integerNode('captured_body_length')
143+
->scalarNode('captured_body_length')
144+
->beforeNormalization()
145+
->always(function ($maxLength) {
146+
if (null === $maxLength) {
147+
return null;
148+
}
149+
150+
if (!is_int($maxLength)) {
151+
$invalidConfiguration = new InvalidConfigurationException('The child node "captured_body_length" at path "httplug.profiling" must be an integer or null.');
152+
$invalidConfiguration->setPath('httplug.profiling');
153+
154+
throw $invalidConfiguration;
155+
}
156+
157+
return $maxLength;
158+
})
159+
->end()
144160
->defaultValue(0)
145-
->info('Limit long HTTP message bodies to x characters. If set to 0 we do not read the message body. Only available with the default formatter (FullHttpMessageFormatter).')
161+
->info('Limit long HTTP message bodies to x characters. If set to 0 we do not read the message body. If null the body will not be truncated. Only available with the default formatter (FullHttpMessageFormatter).')
146162
->end()
147163
->end()
148164
->end()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
httplug:
2+
profiling:
3+
captured_body_length: foo
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
httplug:
2+
profiling:
3+
captured_body_length: ~

tests/Unit/DependencyInjection/ConfigurationTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,4 +395,22 @@ public function testCacheConfigMustHavePool()
395395
$file = __DIR__.'/../../Resources/Fixtures/config/cache_config_with_no_pool.yml';
396396
$this->assertProcessedConfigurationEquals([], [$file]);
397397
}
398+
399+
public function testLimitlessCapturedBodyLength()
400+
{
401+
$file = __DIR__.'/../../Resources/Fixtures/config/limitless_captured_body_length.yml';
402+
$config = $this->emptyConfig;
403+
$config['profiling']['captured_body_length'] = null;
404+
$this->assertProcessedConfigurationEquals($config, [$file]);
405+
}
406+
407+
/**
408+
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
409+
* @expectedExceptionMessage The child node "captured_body_length" at path "httplug.profiling" must be an integer or null.
410+
*/
411+
public function testInvalidCapturedBodyLengthString()
412+
{
413+
$file = __DIR__.'/../../Resources/Fixtures/config/invalid_captured_body_length.yml';
414+
$this->assertProcessedConfigurationEquals([], [$file]);
415+
}
398416
}

0 commit comments

Comments
 (0)