 core/includes/common.inc                           |   19 +------
 .../Core/EventSubscriber/HtmlViewSubscriber.php    |   58 +++++++++++++++++++-
 .../Core/Page/DefaultHtmlFragmentRenderer.php      |    6 +-
 .../system/Tests/Bootstrap/PageCacheTest.php       |    3 +-
 .../Tests/Cache/PageCacheTagsIntegrationTest.php   |   10 +++-
 .../system/Tests/Cache/PageCacheTagsTestBase.php   |    2 +
 6 files changed, 76 insertions(+), 22 deletions(-)

diff --git a/core/includes/common.inc b/core/includes/common.inc
index a2226c8..2d6753c 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -3241,7 +3241,7 @@ function drupal_page_set_cache(Response $response, Request $request) {
         // because by the time it is read, the configuration might change.
         'page_compressed' => $page_compressed,
       ),
-      'tags' => array('content' => TRUE) + drupal_cache_tags_page_get($response),
+      'tags' => Drupal\Core\EventSubscriber\HtmlViewSubscriber::convertHeaderToCacheTags($response->headers->get('X-Drupal-Cache-Tags')),
       'expire' => Cache::PERMANENT,
       'created' => REQUEST_TIME,
     );
@@ -4494,23 +4494,6 @@ function drupal_render_collect_cache_tags($element, $tags = array()) {
 }
 
 /**
- * Return the cache tags that were stored during drupal_render_page().
- *
- * @param \Symfony\Component\HttpFoundation\Response $response
- *   The response object.
- * @return array
- *   An array of cache tags.
- *
- * @see \Drupal\Core\EventSubscriber\HtmlViewSubscriber::onHtmlPage()
- */
-function drupal_cache_tags_page_get(Response $response) {
-  if (($tags = $response->headers->get('cache_tags')) && $tags = unserialize($tags)) {
-    return $tags;
-  }
-  return array();
-}
-
-/**
  * Prepares an element for caching based on a query.
  *
  * This smart caching strategy saves Drupal from querying and rendering to HTML
diff --git a/core/lib/Drupal/Core/EventSubscriber/HtmlViewSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/HtmlViewSubscriber.php
index 69e80cd..0975b05 100644
--- a/core/lib/Drupal/Core/EventSubscriber/HtmlViewSubscriber.php
+++ b/core/lib/Drupal/Core/EventSubscriber/HtmlViewSubscriber.php
@@ -77,7 +77,7 @@ public function onHtmlPage(GetResponseForControllerResultEvent $event) {
       // recommended.
       $response = new Response((string) $this->pageRenderer->render($page), $page->getStatusCode());
       if ($tags = $page->getCacheTags()) {
-        $response->headers->set('cache_tags', serialize($tags));
+        $response->headers->set('X-Drupal-Cache-Tags', $this->convertCacheTagsToHeader($tags));
       }
       if ($keys = $page->getCacheKeys()) {
         $response->headers->set('cache_keys', serialize($keys));
@@ -105,4 +105,60 @@ static function getSubscribedEvents() {
     return $events;
   }
 
+  /**
+   * Converts a cache tags array into a X-Drupal-Cache-Tags header value.
+   *
+   * @param array $tags
+   *   Associative array of cache tags to flatten.
+   *
+   * @return string
+   *   A space-separated list of flattened cache tag identifiers.
+   */
+  public static function convertCacheTagsToHeader(array $tags) {
+    $flat_tags = array();
+    foreach ($tags as $namespace => $values) {
+      if (is_array($values)) {
+        foreach ($values as $value) {
+          $flat_tags[] = "$namespace:$value";
+        }
+      }
+      else {
+        $flat_tags[] = "$namespace:$values";
+      }
+    }
+    return implode(' ', $flat_tags);
+  }
+
+  /**
+   * Converts a X-Drupal-Cache-Tags header value into a cache tags array.
+   *
+   * @param string $tags_header
+   *   A space-separated list of flattened cache tag identifiers.
+   *
+   * @return array
+   *   Associative array of cache tags to flatten.
+   */
+  public static function convertHeaderToCacheTags($tags_header) {
+    if (!is_string($tags_header) || strlen(trim($tags_header)) == 0) {
+      return array();
+    }
+
+    $flat_tags = explode(' ', trim($tags_header));
+    $tags = array();
+    foreach ($flat_tags as $flat_tag) {
+      list($namespace, $value) = explode(':', $flat_tag);
+      if (!isset($tags[$namespace])) {
+        $tags[$namespace] = $value;
+      }
+      // Multiple values in this namespace.
+      else {
+        if (!is_array($tags[$namespace])) {
+          $tags[$namespace] = array($tags[$namespace]);
+        }
+        $tags[$namespace][] = $value;
+      }
+    }
+    return $tags;
+  }
+
 }
diff --git a/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php b/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php
index e1a9029..8de2067 100644
--- a/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php
+++ b/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php
@@ -55,7 +55,11 @@ public function render(HtmlFragment $fragment, $status_code = 200) {
     $page->setBodyBottom(drupal_render($page_array['page_bottom']));
     $page->setContent(drupal_render($page_array));
     // Collect cache tags for all the content in all the regions on the page.
-    $page->setCacheTags($page_array['#cache']['tags']);
+    $tags = $page_array['#cache']['tags'];
+    // Enforce the generic "content" cache tag on all pages.
+    // @todo Remove the "content" cache tag. @see https://drupal.org/node/2124957
+    $tags['content'] = TRUE;
+    $page->setCacheTags($tags);
     $page->setStatusCode($status_code);
 
     return $page;
diff --git a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php
index 7f961d3..056a908 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/PageCacheTest.php
@@ -65,7 +65,8 @@ function testPageCacheTags() {
     $cid_parts = array(url($path, array('absolute' => TRUE)), 'html');
     $cid = sha1(implode(':', $cid_parts));
     $cache_entry = \Drupal::cache('page')->get($cid);
-    $this->assertIdentical($cache_entry->tags, array('content:1', 'system_test_cache_tags_page:1', 'pre_render:1'));
+    sort($cache_entry->tags);
+    $this->assertIdentical($cache_entry->tags, array('content:1', 'pre_render:1', 'system_test_cache_tags_page:1'));
 
     Cache::invalidateTags($tags);
     $this->drupalGet($path);
diff --git a/core/modules/system/lib/Drupal/system/Tests/Cache/PageCacheTagsIntegrationTest.php b/core/modules/system/lib/Drupal/system/Tests/Cache/PageCacheTagsIntegrationTest.php
index b245c34..1f0c39e 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Cache/PageCacheTagsIntegrationTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Cache/PageCacheTagsIntegrationTest.php
@@ -96,14 +96,22 @@ function testPageCacheTags() {
    *   The expected cache tags for the page cache entry of the given $path.
    */
   protected function verifyPageCacheTags($path, $expected_tags) {
+    sort($expected_tags);
     $this->drupalGet($path);
     $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
+    $actual_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags'));
+    sort($actual_tags);
+    $this->assertIdentical($actual_tags, $expected_tags);
     $this->drupalGet($path);
+    $actual_tags = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags'));
+    sort($actual_tags);
     $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'HIT');
+    $this->assertIdentical($actual_tags, $expected_tags);
     $cid_parts = array(url($path, array('absolute' => TRUE)), 'html');
     $cid = sha1(implode(':', $cid_parts));
     $cache_entry = \Drupal::cache('page')->get($cid);
-    $this->assertIdentical($cache_entry->tags, $expected_tags);
+    sort($cache_entry->tags);
+    $this->assertEqual($cache_entry->tags, $expected_tags);
   }
 
 }
diff --git a/core/modules/system/lib/Drupal/system/Tests/Cache/PageCacheTagsTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Cache/PageCacheTagsTestBase.php
index 194976a..4dfc88c 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Cache/PageCacheTagsTestBase.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Cache/PageCacheTagsTestBase.php
@@ -49,6 +49,8 @@ protected function verifyPageCache($path, $hit_or_miss, $tags = FALSE) {
       $cid_parts = array(url($path, array('absolute' => TRUE)), 'html');
       $cid = sha1(implode(':', $cid_parts));
       $cache_entry = \Drupal::cache('page')->get($cid);
+      sort($cache_entry->tags);
+      sort($tags);
       $this->assertIdentical($cache_entry->tags, $tags);
     }
   }
