Skip to content

Allow to disable body limitation size #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 18 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being late, but wouldn't it be more straight-forward to use something like ifTrue(...)->thenInvalid() construct?

What I have in mind would be something like this:

->scalarNode('captured_body_length')
    ->validate()
        ->ifTrue(function ($v) {
            return null !== $v && !is_int($v);
        })
        ->thenInvalid('The child node "captured_body_length" at path "httplug.profiling" must be an integer or null ("%s" given).')
    ->end()
->end()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. i created #323 with your proposed change

$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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
httplug:
profiling:
captured_body_length: foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
httplug:
profiling:
captured_body_length: ~
18 changes: 18 additions & 0 deletions tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}