Chris@0: getStatusCode(), []); Chris@0: Chris@0: $this->originalHtmlResponse = $response; Chris@0: Chris@0: $this->populateBasedOnOriginalHtmlResponse(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the original HTML response. Chris@0: * Chris@0: * @return \Drupal\Core\Render\HtmlResponse Chris@0: * The original HTML response. Chris@0: */ Chris@0: public function getOriginalHtmlResponse() { Chris@0: return $this->originalHtmlResponse; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Populates this BigPipeResponse object based on the original HTML response. Chris@0: */ Chris@0: protected function populateBasedOnOriginalHtmlResponse() { Chris@0: // Clone the HtmlResponse's data into the new BigPipeResponse. Chris@0: $this->headers = clone $this->originalHtmlResponse->headers; Chris@0: $this Chris@0: ->setStatusCode($this->originalHtmlResponse->getStatusCode()) Chris@0: ->setContent($this->originalHtmlResponse->getContent()) Chris@0: ->setAttachments($this->originalHtmlResponse->getAttachments()) Chris@0: ->addCacheableDependency($this->originalHtmlResponse->getCacheableMetadata()); Chris@0: Chris@0: // A BigPipe response can never be cached, because it is intended for a Chris@0: // single user. Chris@0: // @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.1 Chris@0: $this->setPrivate(); Chris@0: Chris@0: // Inform surrogates how they should handle BigPipe responses: Chris@0: // - "no-store" specifies that the response should not be stored in cache; Chris@0: // it is only to be used for the original request Chris@0: // - "content" identifies what processing surrogates should perform on the Chris@0: // response before forwarding it. We send, "BigPipe/1.0", which surrogates Chris@0: // should not process at all, and in fact, they should not even buffer it Chris@0: // at all. Chris@0: // @see http://www.w3.org/TR/edge-arch/ Chris@0: $this->headers->set('Surrogate-Control', 'no-store, content="BigPipe/1.0"'); Chris@0: Chris@0: // Add header to support streaming on NGINX + php-fpm (nginx >= 1.5.6). Chris@0: $this->headers->set('X-Accel-Buffering', 'no'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the BigPipe service to use. Chris@0: * Chris@0: * @param \Drupal\big_pipe\Render\BigPipe $big_pipe Chris@0: * The BigPipe service. Chris@0: */ Chris@0: public function setBigPipeService(BigPipe $big_pipe) { Chris@0: $this->bigPipe = $big_pipe; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function sendContent() { Chris@0: $this->bigPipe->sendContent($this); Chris@0: Chris@0: // All BigPipe placeholders are processed, so update this response's Chris@0: // attachments. Chris@0: unset($this->attachments['big_pipe_placeholders']); Chris@0: unset($this->attachments['big_pipe_nojs_placeholders']); Chris@0: Chris@0: return $this; Chris@0: } Chris@0: Chris@0: }