...terface.php => CacheableStreamedResponseInterface.php} | 15 ++++++++++----- core/modules/big_pipe/src/Render/BigPipe.php | 3 +++ core/modules/big_pipe/src/Render/BigPipeResponse.php | 6 +++--- core/modules/page_cache/src/StackMiddleware/PageCache.php | 8 ++++---- .../page_cache_test/src/PageCacheTestController.php | 4 ++-- .../page_cache_test/src/PageCacheTestStreamedResponse.php | 6 +++--- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/core/lib/Drupal/Core/Render/StreamedResponseInterface.php b/core/lib/Drupal/Core/Render/CacheableStreamedResponseInterface.php similarity index 11% rename from core/lib/Drupal/Core/Render/StreamedResponseInterface.php rename to core/lib/Drupal/Core/Render/CacheableStreamedResponseInterface.php index 524e1d5..ee83ba2 100644 --- a/core/lib/Drupal/Core/Render/StreamedResponseInterface.php +++ b/core/lib/Drupal/Core/Render/CacheableStreamedResponseInterface.php @@ -3,15 +3,20 @@ namespace Drupal\Core\Render; /** - * Defines an interface for streamed responses. + * Defines an interface for cacheable streamed responses. + * + * @internal + * @todo Make public once code/modules other than BigPipe start using this. + * @todo https://www.drupal.org/node/2577631 will introduce + * StreamedResponseInterface, consider making this interface extend that one. */ -interface StreamedResponseInterface { +interface CacheableStreamedResponseInterface { /** - * Returns the entire streamed response, if possible. + * Returns the entire streamed response for caching, if possible. * - * @return FALSE|\Symfony\Component\HttpFoundation\Response + * @return FALSE|\Drupal\Core\Cache\CacheableResponseInterface */ - public function getStreamedResponse(); + public function getCacheableStreamedResponse(); } diff --git a/core/modules/big_pipe/src/Render/BigPipe.php b/core/modules/big_pipe/src/Render/BigPipe.php index 3deb140..6e8e991 100644 --- a/core/modules/big_pipe/src/Render/BigPipe.php +++ b/core/modules/big_pipe/src/Render/BigPipe.php @@ -537,6 +537,9 @@ protected function filterEmbeddedResponse(Request $fake_request, Response $embed * * @param string $post_body * The HTML response's content after the closing tag. + * + * @return string + * The streamed HTML. */ protected function sendPostBody($post_body) { print ''; diff --git a/core/modules/big_pipe/src/Render/BigPipeResponse.php b/core/modules/big_pipe/src/Render/BigPipeResponse.php index 3dba160..b8c3b3e 100644 --- a/core/modules/big_pipe/src/Render/BigPipeResponse.php +++ b/core/modules/big_pipe/src/Render/BigPipeResponse.php @@ -3,7 +3,7 @@ namespace Drupal\big_pipe\Render; use Drupal\Core\Render\HtmlResponse; -use Drupal\Core\Render\StreamedResponseInterface; +use Drupal\Core\Render\CacheableStreamedResponseInterface; /** * A response that is sent in chunks by the BigPipe service. @@ -24,7 +24,7 @@ * * @todo Will become obsolete with https://www.drupal.org/node/2577631 */ -class BigPipeResponse extends HtmlResponse implements StreamedResponseInterface { +class BigPipeResponse extends HtmlResponse implements CacheableStreamedResponseInterface { protected $requestHasSession; @@ -140,7 +140,7 @@ public function sendContent() { /** * {@inheritdoc} */ - public function getStreamedResponse() { + public function getCacheableStreamedResponse() { // We can only return the streamed response if it was collected. And we only // collect it in one case, see … if ($this->finalHtmlResponse === FALSE) { diff --git a/core/modules/page_cache/src/StackMiddleware/PageCache.php b/core/modules/page_cache/src/StackMiddleware/PageCache.php index 803f640..fc73ac0 100644 --- a/core/modules/page_cache/src/StackMiddleware/PageCache.php +++ b/core/modules/page_cache/src/StackMiddleware/PageCache.php @@ -7,7 +7,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\PageCache\RequestPolicyInterface; use Drupal\Core\PageCache\ResponsePolicyInterface; -use Drupal\Core\Render\StreamedResponseInterface; +use Drupal\Core\Render\CacheableStreamedResponseInterface; use Drupal\Core\Site\Settings; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\Request; @@ -88,8 +88,8 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = */ public function terminate(Request $request, Response $response) { // Also cache streamed responses, if they support it. - if ($response instanceof StreamedResponseInterface) { - $streamed_response = $response->getStreamedResponse(); + if ($response instanceof CacheableStreamedResponseInterface) { + $streamed_response = $response->getCacheableStreamedResponse(); if ($streamed_response !== FALSE) { $this->storeResponse($request, $streamed_response); } @@ -233,7 +233,7 @@ protected function fetch(Request $request, $type = self::MASTER_REQUEST, $catch // 'terminate' phase/event. Already set the 'X-Drupal-Cache' header, so that // header is present as expected. // @see ::terminate() - elseif ($response instanceof StreamedResponseInterface) { + elseif ($response instanceof CacheableStreamedResponseInterface) { // Mark response as a cache miss. $response->headers->set('X-Drupal-Cache', 'MISS'); return $response; diff --git a/core/modules/page_cache/tests/modules/page_cache_test/src/PageCacheTestController.php b/core/modules/page_cache/tests/modules/page_cache_test/src/PageCacheTestController.php index 17d014f..0809cfe 100644 --- a/core/modules/page_cache/tests/modules/page_cache_test/src/PageCacheTestController.php +++ b/core/modules/page_cache/tests/modules/page_cache_test/src/PageCacheTestController.php @@ -18,14 +18,14 @@ public function symfonyStreamedResponse() { * Returns a StreamedResponseInterface Response, with untracked stream. */ public function streamedResponseInterfaceUntracked() { - return new PageCacheTestStreamedResponse(FALSE); + return new PageCacheTestCacheableStreamedResponse(FALSE); } /** * Returns a StreamedResponseInterface Response, with tracked stream. */ public function streamedResponseInterfaceTracked() { - return new PageCacheTestStreamedResponse((new HtmlResponse('Hello world!'))->setExpires(\DateTime::createFromFormat('j-M-Y H:i:s T', '19-Nov-1978 05:00:00 UTC'))); + return new PageCacheTestCacheableStreamedResponse((new HtmlResponse('Hello world!'))->setExpires(\DateTime::createFromFormat('j-M-Y H:i:s T', '19-Nov-1978 05:00:00 UTC'))); } } diff --git a/core/modules/page_cache/tests/modules/page_cache_test/src/PageCacheTestStreamedResponse.php b/core/modules/page_cache/tests/modules/page_cache_test/src/PageCacheTestStreamedResponse.php index 5e20353..3042d6a 100644 --- a/core/modules/page_cache/tests/modules/page_cache_test/src/PageCacheTestStreamedResponse.php +++ b/core/modules/page_cache/tests/modules/page_cache_test/src/PageCacheTestStreamedResponse.php @@ -5,10 +5,10 @@ use Drupal\Core\Cache\CacheableResponseInterface; use Drupal\Core\Cache\CacheableResponseTrait; -use Drupal\Core\Render\StreamedResponseInterface; +use Drupal\Core\Render\CacheableStreamedResponseInterface; use Symfony\Component\HttpFoundation\Response; -class PageCacheTestStreamedResponse extends Response implements StreamedResponseInterface, CacheableResponseInterface { +class PageCacheTestCacheableStreamedResponse extends Response implements CacheableStreamedResponseInterface, CacheableResponseInterface { use CacheableResponseTrait; @@ -19,7 +19,7 @@ public function __construct($streamed_response) { parent::__construct('', 200, []); } - public function getStreamedResponse() { + public function getCacheableStreamedResponse() { return $this->streamedResponse; } }