 core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php | 6 ++++--
 core/modules/simpletest/src/WebTestBase.php                       | 7 +++++++
 sites/example.settings.local.php                                  | 7 +++++++
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php
index 251b920..48b53bd 100644
--- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php
+++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php
@@ -116,8 +116,10 @@ public function onRespond(FilterResponseEvent $event) {
     $response->headers->set('X-Frame-Options', 'SAMEORIGIN', FALSE);
 
     // Expose the cache contexts and cache tags associated with this page in a
-    // X-Drupal-Cache-Contexts and X-Drupal-Cache-Tags header respectively.
-    if ($response instanceof CacheableResponseInterface) {
+    // X-Drupal-Cache-Contexts and X-Drupal-Cache-Tags header respectively, when
+    // either a reverse proxy is being used (so the reverse proxy or CDN can be
+    // invalidated when appropriate) or when developing/debugging.
+    if ((Settings::get('reverse_proxy', FALSE) || Settings::get('send_cacheability_headers', FALSE)) && $response instanceof CacheableResponseInterface) {
       $response_cacheability = $response->getCacheableMetadata();
       $response->headers->set('X-Drupal-Cache-Tags', implode(' ', $response_cacheability->getCacheTags()));
       $response->headers->set('X-Drupal-Cache-Contexts', implode(' ', $this->cacheContextsManager->optimizeTokens($response_cacheability->getCacheContexts())));
diff --git a/core/modules/simpletest/src/WebTestBase.php b/core/modules/simpletest/src/WebTestBase.php
index 2ac0d4b..dad9dbf 100644
--- a/core/modules/simpletest/src/WebTestBase.php
+++ b/core/modules/simpletest/src/WebTestBase.php
@@ -742,6 +742,13 @@ protected function prepareSettings() {
       'value' => FALSE,
       'required' => TRUE,
     ];
+
+    // Send cacheability headers so tests can check their values.
+    $settings['settings']['send_cacheability_headers'] = (object) [
+      'value' => TRUE,
+      'required' => TRUE,
+    ];
+
     $this->writeSettings($settings);
     // Allow for test-specific overrides.
     $settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSite . '/settings.testing.php';
diff --git a/sites/example.settings.local.php b/sites/example.settings.local.php
index 34b4e19..0711fb9 100644
--- a/sites/example.settings.local.php
+++ b/sites/example.settings.local.php
@@ -59,6 +59,13 @@
 $settings['cache']['bins']['render'] = 'cache.backend.null';
 
 /**
+ * Send cacheablity headers for debugging purposes.
+ *
+ * By default, cacheability headers are only sent when behind a reverse proxy.
+ */
+$settings['send_cacheability_headers'] = TRUE;
+
+/**
  * Allow test modules and themes to be installed.
  *
  * Drupal ignores test modules and themes by default for performance reasons.
