From 788d85d97619a38d36c11a26566298dd439887a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20DECOOL?= Date: Tue, 5 Mar 2019 21:29:33 +0100 Subject: [PATCH 1/4] Allow to disable body limitation size --- src/DependencyInjection/Configuration.php | 13 +++++++++++-- .../config/limitless_captured_body_length.yml | 3 +++ .../Unit/DependencyInjection/ConfigurationTest.php | 8 ++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/Resources/Fixtures/config/limitless_captured_body_length.yml diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 22b7a95e..4c52aa9a 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -140,9 +140,18 @@ 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; + } + + return (int) $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/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..3c702193 100644 --- a/tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/tests/Unit/DependencyInjection/ConfigurationTest.php @@ -395,4 +395,12 @@ 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]); + } } From b4127a8c1b0250a040db0530c15e2ccf36162403 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20DECOOL?= Date: Tue, 5 Mar 2019 21:34:42 +0100 Subject: [PATCH 2/4] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) 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 From f428cac06410368f761bc6ef2aa113989f186f57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20DECOOL?= Date: Tue, 5 Mar 2019 21:35:52 +0100 Subject: [PATCH 3/4] CS --- src/DependencyInjection/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 4c52aa9a..b81a7c76 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -142,7 +142,7 @@ public function getConfigTreeBuilder() ->scalarNode('formatter')->defaultNull()->end() ->scalarNode('captured_body_length') ->beforeNormalization() - ->always(function($maxLength) { + ->always(function ($maxLength) { if (null === $maxLength) { return null; } From 0a1dc87d13c17f3f59be0383684d5f784cacb830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20DECOOL?= Date: Wed, 6 Mar 2019 08:22:38 +0100 Subject: [PATCH 4/4] Throw an InvalidConfigurationException if httplug.profiling.captured_body_length is not an integer or null --- src/DependencyInjection/Configuration.php | 9 ++++++++- .../Fixtures/config/invalid_captured_body_length.yml | 3 +++ tests/Unit/DependencyInjection/ConfigurationTest.php | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/Resources/Fixtures/config/invalid_captured_body_length.yml diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index b81a7c76..84e2f88b 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -147,7 +147,14 @@ public function getConfigTreeBuilder() return null; } - return (int) $maxLength; + 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) 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/Unit/DependencyInjection/ConfigurationTest.php b/tests/Unit/DependencyInjection/ConfigurationTest.php index 3c702193..570e7482 100644 --- a/tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/tests/Unit/DependencyInjection/ConfigurationTest.php @@ -403,4 +403,14 @@ public function testLimitlessCapturedBodyLength() $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]); + } }