You are here

protected function BigPipeResponse::populateBasedOnOriginalHtmlResponse in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/big_pipe/src/Render/BigPipeResponse.php \Drupal\big_pipe\Render\BigPipeResponse::populateBasedOnOriginalHtmlResponse()

Populates this BigPipeResponse object based on the original HTML response.

1 call to BigPipeResponse::populateBasedOnOriginalHtmlResponse()
BigPipeResponse::__construct in core/modules/big_pipe/src/Render/BigPipeResponse.php
Constructs a new BigPipeResponse.

File

core/modules/big_pipe/src/Render/BigPipeResponse.php, line 70

Class

BigPipeResponse
A response that is sent in chunks by the BigPipe service.

Namespace

Drupal\big_pipe\Render

Code

protected function populateBasedOnOriginalHtmlResponse() {

  // Clone the HtmlResponse's data into the new BigPipeResponse.
  $this->headers = clone $this->originalHtmlResponse->headers;
  $this
    ->setStatusCode($this->originalHtmlResponse
    ->getStatusCode())
    ->setContent($this->originalHtmlResponse
    ->getContent())
    ->setAttachments($this->originalHtmlResponse
    ->getAttachments())
    ->addCacheableDependency($this->originalHtmlResponse
    ->getCacheableMetadata());

  // A BigPipe response can never be cached, because it is intended for a
  // single user.
  // @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.1
  $this
    ->setPrivate();

  // Inform surrogates how they should handle BigPipe responses:
  // - "no-store" specifies that the response should not be stored in cache;
  //   it is only to be used for the original request
  // - "content" identifies what processing surrogates should perform on the
  //   response before forwarding it. We send, "BigPipe/1.0", which surrogates
  //   should not process at all, and in fact, they should not even buffer it
  //   at all.
  // @see http://www.w3.org/TR/edge-arch/
  $this->headers
    ->set('Surrogate-Control', 'no-store, content="BigPipe/1.0"');

  // Add header to support streaming on NGINX + php-fpm (nginx >= 1.5.6).
  $this->headers
    ->set('X-Accel-Buffering', 'no');
}