diff --git a/CHANGELOG.md b/CHANGELOG.md index e195912f..37887f94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee - Removed `twig/twig` dependency - Removed hard dependency on `php-http/cache-plugin`. If you want to use the cache plugin, you need to require it in your project. +- Allow to set `httpplug.profiling.captured_body_length` configuration to `null` + to avoid body limitation size. ### Fixed diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 22b7a95e..84e2f88b 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -140,9 +140,25 @@ public function getConfigTreeBuilder() ->defaultValue($this->debug) ->end() ->scalarNode('formatter')->defaultNull()->end() - ->integerNode('captured_body_length') + ->scalarNode('captured_body_length') + ->beforeNormalization() + ->always(function ($maxLength) { + if (null === $maxLength) { + return null; + } + + if (!is_int($maxLength)) { + $invalidConfiguration = new InvalidConfigurationException('The child node "captured_body_length" at path "httplug.profiling" must be an integer or null.'); + $invalidConfiguration->setPath('httplug.profiling'); + + throw $invalidConfiguration; + } + + return $maxLength; + }) + ->end() ->defaultValue(0) - ->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).') + ->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).') ->end() ->end() ->end() diff --git a/tests/Resources/Fixtures/config/invalid_captured_body_length.yml b/tests/Resources/Fixtures/config/invalid_captured_body_length.yml new file mode 100644 index 00000000..35c1928c --- /dev/null +++ b/tests/Resources/Fixtures/config/invalid_captured_body_length.yml @@ -0,0 +1,3 @@ +httplug: + profiling: + captured_body_length: foo diff --git a/tests/Resources/Fixtures/config/limitless_captured_body_length.yml b/tests/Resources/Fixtures/config/limitless_captured_body_length.yml new file mode 100644 index 00000000..1c56a8c3 --- /dev/null +++ b/tests/Resources/Fixtures/config/limitless_captured_body_length.yml @@ -0,0 +1,3 @@ +httplug: + profiling: + captured_body_length: ~ diff --git a/tests/Unit/DependencyInjection/ConfigurationTest.php b/tests/Unit/DependencyInjection/ConfigurationTest.php index 7a937ca2..570e7482 100644 --- a/tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/tests/Unit/DependencyInjection/ConfigurationTest.php @@ -395,4 +395,22 @@ public function testCacheConfigMustHavePool() $file = __DIR__.'/../../Resources/Fixtures/config/cache_config_with_no_pool.yml'; $this->assertProcessedConfigurationEquals([], [$file]); } + + public function testLimitlessCapturedBodyLength() + { + $file = __DIR__.'/../../Resources/Fixtures/config/limitless_captured_body_length.yml'; + $config = $this->emptyConfig; + $config['profiling']['captured_body_length'] = null; + $this->assertProcessedConfigurationEquals($config, [$file]); + } + + /** + * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + * @expectedExceptionMessage The child node "captured_body_length" at path "httplug.profiling" must be an integer or null. + */ + public function testInvalidCapturedBodyLengthString() + { + $file = __DIR__.'/../../Resources/Fixtures/config/invalid_captured_body_length.yml'; + $this->assertProcessedConfigurationEquals([], [$file]); + } }