Append all response.

@param \Psr\Http\Message\ResponseInterface $response

@return \Psr\Http\Message\ResponseInterface

@author Seven Du <shiweidu@outlook.com>
354767
protected function appendAllResponse(ResponseInterface $response): ResponseInterface
    {
        if ($this->append) {
            $this->cors->setResponse('psr-7', $response);
            $this->cors->handle();

            return $this->cors->getResponse();
        }

        return $response;
    }
549160
public function onceResponse(string $file, ResponseInterface $response) : ResponseInterface
    {
        return $this->includeResponse('once', $file, $response);
    }
39960
private function withText(ResponseInterface $response, $text)
    {
        if (is_array($text)) {
            $text = implode(PHP_EOL, $text);
        }

        return $this
            ->withNewBody($response, $text)
            ->withHeader('Content-Type', 'text/plain');
    }
1319594
protected function returnResponse(ResponseInterface $response): ResponseInterface
    {
        $this->nextHandler = null;
        reset($this->handlers);
        return $response;
    }
320071
public function merge(Response $response)
    {
        $meta       = $response->getRaw('meta');
        $data       = $response->get();
        $pagination = $response->hasPages()
            ? $response->getRaw('pagination')
            : [];

        $old = $this->get();

        if ($this->isCollection($old) && $this->isCollection($data)) {
            $old = !($old instanceof Collection) ?: $old->toArray();
            $new = !($data instanceof Collection) ?: $data->toArray();

            return new Response($meta, array_merge($old, $new), $pagination);
        }

        if ($this->isRecord($old) && $this->isRecord($data)) {
            return new Response($meta, [$old, $data], $pagination);
        }

        throw new IncompatibleResponseException('The response contents cannot be merged');
    }
478788
public function sendResponse(ResponseInterface $response)
    {
        $e = $this->getEvent();
        $e->setResponse($response);

        $e->getApplication()->getEventManager()->trigger(MvcEvent::EVENT_FINISH, $e);
        exit();
    }
1324628
protected function applyDefaultResponseHeaders(ResponseInterface $response) : ResponseInterface
    {
        foreach ($this->defaultResponseHeaders as $name => $value) {
            if (! $response->hasHeader($name)) {
                $response = $response->withHeader($name, $value);
            }
        }

        return $response;
    }
1014376
public static function getContent(ResponseInterface $response)
    {
        $body = $response->getBody()->__toString();
        if (strpos($response->getHeaderLine('Content-Type'), 'application/json') === 0) {
            $content = json_decode($body, true);
            if (JSON_ERROR_NONE === json_last_error()) {
                return $content;
            }
        }

        return $body;
    }
808342
protected function getBatchResponses(ResponseInterface $response)
    {
        $results = JsonRpc\json_decode((string) $response->getBody(), true);

        return array_map(function (array $result) use ($response) {
            return $this->messageFactory->createResponse(
                $response->getStatusCode(),
                $response->getHeaders(),
                $result
            );
        }, $results);
    }
1367363
protected function render(ResponseInterface $response)
    {
        $stream = new Stream('php://memory', 'rw+');
        $content = $this->getEngine()
            ->parse($this->getTemplate())
            ->process($this->getData())
        ;
        $stream->write($content);

        $response = $response->withBody($stream);
        return $response;
    }
549955
protected function responseWithHeaders($response)
    {
        foreach ($this->getHeaders() as $key => $value) {
            $response->headers->set($key, $value);
        }

        return $response;
    }
383773
private function decorateResponse(ResponseInterface $response)
    {
        if ($response instanceof Http\Response) {
            return $response;
        }

        return new Http\Response($this, $response);
    }
1069968
public static function of(ResponseInterface $response): self
	{
		return new static(
			$response->getStatusCode(),
			$response->getHeaders(),
			$response->getBody(),
			$response->getProtocolVersion(),
			$response->getReasonPhrase()
		);
	}
5709
protected function serveHeaders(ResponseInterface $response)
    {
        header_remove('X-Powered-By');
        foreach ($response->getHeaders() as $header => $values) {
            header($header . ': ' . array_shift($values), true);
            foreach ($values as $value) {
                header($header . ': ' . $value, false);
            }
        }
    }
1250956
protected function wrapResponse($response)
    {
        $statusCode = 200;
        $headers = [];

        if (false !== (strpos($response, "\r\n\r\n")) && false !== strpos($this->scheme, 'http')) {
            list($responseHeaders, $response) = explode("\r\n\r\n", $response, 2);
            $responseHeaders = preg_split('/\r\n/', $responseHeaders, null, PREG_SPLIT_NO_EMPTY);

            $code = array_shift($responseHeaders);
            list(, $statusCode) = explode(' ', $code);
            $headers = [];
            array_map(function ($headerLine) use (&$headers) {
                list($key, $value) = explode(':', $headerLine, 2);
                $headers[$key] = trim($value);
                unset($headerLine, $key, $value);
            }, $responseHeaders);

            if (isset($headers['Content-Encoding'])) {
                $response = zlib_decode($response);
            }
            unset($responseHeaders, $code);
        }

        return new Response($response, $statusCode, $headers);
    }
1296089
protected function generateResponse(ResponseInterface $response): DepartureBoardResponse
    {
        $json = $this->validateJson($response);
        if (isset($json['DepartureBoard'])) {
            return DepartureBoardResponse::createFromArray($json['DepartureBoard']);
        }

        return new DepartureBoardResponse();
    }
707086
public function sendHeaders(Response $response)
    {
        if (headers_sent()) {
            return $response;
        }

        $statusCode = $response->getStatusCode();
        $protocolVersion = $response->getProtocolVersion();
        $statusText = $response->getReasonPhrase();
        foreach ($response->headers->allPreserveCase() as $name => $values) {
            foreach ($values as $value) {
                header($name.': '.$value, false, $statusCode);
            }
        }
        $statusHeader = sprintf('HTTP/%s %s %s', $protocolVersion, $statusCode, $statusText);
        header($statusHeader, true, $statusCode);

        return $response;
    }