/**
  * {@inheritDoc}
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out = null)
 {
     $this->toolbar->addDataCollector(new Request($request));
     if (null !== $out) {
         $response = $out($request, $response);
     }
     if (!$response->getBody()->isWritable()) {
         $this->logger->debug('Response is not writable. Skipping Prophiler toolbar generation.');
         return $response;
     }
     $headers = $response->getHeader('Content-Type');
     if (count($headers) === 0) {
         $this->logger->debug('Content-Type of response not set. Skipping Prophiler toolbar generation.');
         return $response;
     }
     if ($headers[0] === 'text/html') {
         $response->getBody()->write($this->toolbar->render());
     } else {
         $this->logger->debug('Content-Type of response is not text/html. Skipping Prophiler toolbar generation.');
     }
     return $response;
 }
 /**
  * {@inheritDoc}
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out = null)
 {
     $this->toolbar->addDataCollector(new Request($request));
     if (null !== $out) {
         $response = $out($request, $response);
     }
     if (!$response->getBody()->isWritable()) {
         $this->logger->debug('Response is not writable. Skipping Prophiler toolbar generation.');
         return $response;
     }
     // Allow any HTML content type
     $contentType = $response->getHeaderLine('Content-Type');
     if (!preg_match('#^(?:text/html|application/xhtml\\+xml)\\s*(?:;|$)#', $contentType)) {
         $this->logger->debug('Content-Type of response is not HTML. Skipping Prophiler toolbar generation.');
         return $response;
     }
     // We need to be at the end of the stream when writing
     $body = $response->getBody();
     if (!$body->eof() && $body->isSeekable()) {
         $body->seek(0, SEEK_END);
     }
     $body->write($this->toolbar->render());
     return $response;
 }