/** * @param string $output * @param Runtime $typoScriptRuntime * @return string The message body without the message head */ protected function mergeHttpResponseFromOutput($output, Runtime $typoScriptRuntime) { if (substr($output, 0, 5) === 'HTTP/') { $endOfHeader = strpos($output, "\r\n\r\n"); if ($endOfHeader !== false) { $header = substr($output, 0, $endOfHeader + 4); try { $renderedResponse = Response::createFromRaw($header); /** @var Response $response */ $response = $typoScriptRuntime->getControllerContext()->getResponse(); $response->setStatus($renderedResponse->getStatusCode()); foreach ($renderedResponse->getHeaders()->getAll() as $headerName => $headerValues) { $response->setHeader($headerName, $headerValues[0]); } $output = substr($output, strlen($header)); } catch (\InvalidArgumentException $exception) { } } } return $output; }