diff --git a/CHANGELOG.md b/CHANGELOG.md
index b72402ff..d3f36c22 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/composer.json b/composer.json
index 3639041f..3c5c3755 100644
--- a/composer.json
+++ b/composer.json
@@ -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",
diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php
index f2982d35..424fac67 100644
--- a/src/DependencyInjection/Configuration.php
+++ b/src/DependencyInjection/Configuration.php
@@ -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())
diff --git a/src/DependencyInjection/HttplugExtension.php b/src/DependencyInjection/HttplugExtension.php
index 61a734b5..965e3390 100644
--- a/src/DependencyInjection/HttplugExtension.php
+++ b/src/DependencyInjection/HttplugExtension.php
@@ -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']))
diff --git a/tests/Resources/Fixtures/config/full.php b/tests/Resources/Fixtures/config/full.php
index 8c9def8a..c12643fb 100644
--- a/tests/Resources/Fixtures/config/full.php
+++ b/tests/Resources/Fixtures/config/full.php
@@ -102,6 +102,7 @@
'methods' => ['GET'],
'cache_key_generator' => null,
'respect_response_cache_directives' => ['X-Foo'],
+ 'blacklisted_paths' => ['@/path/not-to-be/cached@']
],
],
'cookie' => [
diff --git a/tests/Resources/Fixtures/config/full.xml b/tests/Resources/Fixtures/config/full.xml
index 607438de..65fe8dd1 100644
--- a/tests/Resources/Fixtures/config/full.xml
+++ b/tests/Resources/Fixtures/config/full.xml
@@ -57,6 +57,7 @@
X-Foo
GET
+ @/path/not-to-be/cached@
diff --git a/tests/Resources/Fixtures/config/full.yml b/tests/Resources/Fixtures/config/full.yml
index 03c97d9a..66f9188f 100644
--- a/tests/Resources/Fixtures/config/full.yml
+++ b/tests/Resources/Fixtures/config/full.yml
@@ -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:
diff --git a/tests/Unit/DependencyInjection/ConfigurationTest.php b/tests/Unit/DependencyInjection/ConfigurationTest.php
index a9fd4ba4..cc593af4 100644
--- a/tests/Unit/DependencyInjection/ConfigurationTest.php
+++ b/tests/Unit/DependencyInjection/ConfigurationTest.php
@@ -43,6 +43,7 @@ class ConfigurationTest extends AbstractExtensionConfigurationTestCase
'stream_factory' => 'httplug.stream_factory',
'config' => [
'methods' => ['GET', 'HEAD'],
+ 'blacklisted_paths' => [],
],
],
'cookie' => [
@@ -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' => [
@@ -354,6 +356,7 @@ public function testCacheConfigDeprecationCompatibility(): void
'config' => [
'methods' => ['GET', 'HEAD'],
'respect_cache_headers' => true,
+ 'blacklisted_paths' => [],
],
]);
$this->assertProcessedConfigurationEquals($config, [$file]);
@@ -372,6 +375,7 @@ public function testCacheConfigDeprecationCompatibilityIssue166(): void
'config' => [
'methods' => ['GET', 'HEAD'],
'respect_cache_headers' => false,
+ 'blacklisted_paths' => [],
],
]);
$this->assertProcessedConfigurationEquals($config, [$file]);