Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
- Configured clients are now tagged with `'httplug.client'`
- Adds a link to profiler page when response is from a Symfony application with
profiler enabled
- Adding `blacklisted_paths` option of `php-http/cache-plugin`

### Changed

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"guzzlehttp/psr7": "^1.0",
"matthiasnoback/symfony-dependency-injection-test": "^3.0",
"nyholm/nsa": "^1.1",
"php-http/cache-plugin": "^1.6",
"php-http/cache-plugin": "^1.7",
"php-http/guzzle6-adapter": "^1.1.1 || ^2.0.1",
"php-http/mock-client": "^1.2",
"php-http/promise": "^1.0",
Expand Down
15 changes: 15 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,21 @@ private function createCachePluginNode()
->integerNode('default_ttl')
->info('The default max age of a Response')
->end()
->arrayNode('blacklisted_paths')
->info('An array of regular expression patterns for paths not to be cached. Defaults to an empty array.')
->defaultValue([])
->beforeNormalization()
->castToArray()
->end()
->prototype('scalar')
->validate()
->ifTrue(function ($v) {
return false === @preg_match($v, '');
})
->thenInvalid('Invalid regular expression for a blacklisted path: %s')
->end()
->end()
->end()
->enumNode('hash_algo')
->info('Hashing algorithm to use')
->values(hash_algos())
Expand Down
4 changes: 4 additions & 0 deletions src/DependencyInjection/HttplugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ private function configurePluginByName($name, Definition $definition, array $con
$options['cache_key_generator'] = new Reference($options['cache_key_generator']);
}

if (empty($options['blacklisted_paths'])) {
unset($options['blacklisted_paths']);
}

$definition
->replaceArgument(0, new Reference($config['cache_pool']))
->replaceArgument(1, new Reference($config['stream_factory']))
Expand Down
1 change: 1 addition & 0 deletions tests/Resources/Fixtures/config/full.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
'methods' => ['GET'],
'cache_key_generator' => null,
'respect_response_cache_directives' => ['X-Foo'],
'blacklisted_paths' => ['@/path/not-to-be/cached@']
],
],
'cookie' => [
Expand Down
1 change: 1 addition & 0 deletions tests/Resources/Fixtures/config/full.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<config default-ttl="42" cache-lifetime="2592000" hash-algo="sha1" cache-key-generator="null">
<respect-response-cache-directive>X-Foo</respect-response-cache-directive>
<method>GET</method>
<blacklisted-paths>@/path/not-to-be/cached@</blacklisted-paths>
</config>
</cache>
<cookie cookie-jar="my_cookie_jar"/>
Expand Down
2 changes: 2 additions & 0 deletions tests/Resources/Fixtures/config/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ httplug:
cache_key_generator: null
respect_response_cache_directives:
- X-Foo
blacklisted_paths:
- '@/path/not-to-be/cached@'
cookie:
cookie_jar: my_cookie_jar
decoder:
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ConfigurationTest extends AbstractExtensionConfigurationTestCase
'stream_factory' => 'httplug.stream_factory',
'config' => [
'methods' => ['GET', 'HEAD'],
'blacklisted_paths' => [],
],
],
'cookie' => [
Expand Down Expand Up @@ -233,6 +234,7 @@ public function testSupportsAllConfigFormats(): void
'methods' => ['GET'],
'cache_key_generator' => null,
'respect_response_cache_directives' => ['X-Foo'],
'blacklisted_paths' => ['@/path/not-to-be/cached@'],
],
],
'cookie' => [
Expand Down Expand Up @@ -354,6 +356,7 @@ public function testCacheConfigDeprecationCompatibility(): void
'config' => [
'methods' => ['GET', 'HEAD'],
'respect_cache_headers' => true,
'blacklisted_paths' => [],
],
]);
$this->assertProcessedConfigurationEquals($config, [$file]);
Expand All @@ -372,6 +375,7 @@ public function testCacheConfigDeprecationCompatibilityIssue166(): void
'config' => [
'methods' => ['GET', 'HEAD'],
'respect_cache_headers' => false,
'blacklisted_paths' => [],
],
]);
$this->assertProcessedConfigurationEquals($config, [$file]);
Expand Down