Set the headers.

@param ResponseInterface $response The response.
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);
            }
        }
    }
556449
private function setErrorFromResponse(Response $response)
    {
        $this->statusCode = $response->getStatus();
        $body = $response->getBody();
        if (isset($body['ErrorInfo'])) {
            $this->errorInfo = $body['ErrorInfo'];
        }
        if (isset($body['ErrorMessage'])) {
            $this->errorMessage = $body['ErrorMessage'];
        }
        if (isset($body['ErrorIdentifier'])) {
            $this->errorIdentifier = $body['ErrorIdentifier'];
        }
    }
857517
public function serve(ResponseInterface $response, $cookies = [])
    {
        if (headers_sent($file, $line)) {
            throw new HeadersSentException(
                'Headers already sent in ' . $file . ' on line ' . $line
            );
        }
        $this->triggerEvent('serve', new \Jivoo\Event($this, [
            'response' => $response,
            'cookies' => $cookies
        ]));
        $this->serveStatus($response);
        $this->serveCookies($cookies);
        $this->serveHeaders($response);
        $this->serveBody($response, $this->compression);
        $this->triggerEvent('served', new \Jivoo\Event($this, [
            'response' => $response,
            'cookies' => $cookies
        ]));
    }
1266505
protected function addResponseHeaders(RequestInterface $request, Response $response)
    {
        $params = $request->getParams();
        $response->setHeader('Via', sprintf('%s GuzzleCache/%s', $request->getProtocolVersion(), Version::VERSION));

        $lookup = ($params['cache.lookup'] === true ? 'HIT' : 'MISS') . ' from GuzzleCache';
        if ($header = $response->getHeader('X-Cache-Lookup')) {
            // Don't add duplicates
            $values = $header->toArray();
            $values[] = $lookup;
            $response->setHeader('X-Cache-Lookup', array_unique($values));
        } else {
            $response->setHeader('X-Cache-Lookup', $lookup);
        }

        if ($params['cache.hit'] === true) {
            $xcache = 'HIT from GuzzleCache';
        } elseif ($params['cache.hit'] == 'error') {
            $xcache = 'HIT_ERROR from GuzzleCache';
        } else {
            $xcache = 'MISS from GuzzleCache';
        }

        if ($header = $response->getHeader('X-Cache')) {
            // Don't add duplicates
            $values = $header->toArray();
            $values[] = $xcache;
            $response->setHeader('X-Cache', array_unique($values));
        } else {
            $response->setHeader('X-Cache', $xcache);
        }

        if ($response->isFresh() === false) {
            $response->addHeader('Warning', sprintf('110 GuzzleCache/%s "Response is stale"', Version::VERSION));
            if ($params['cache.hit'] === 'error') {
                $response->addHeader('Warning', sprintf('111 GuzzleCache/%s "Revalidation failed"', Version::VERSION));
            }
        }
    }
453441
public function checkResponse(ResponseInterface $response)
    {
        if (isset($this->_errorChecker)) {
            $error = call_user_func($this->_errorChecker, $response);
        } else {
            $error = $this->getResponseError($response);
        }

        if ($error) {
            throw new ResponseErrorException($error, $response);
        }
    }
1273745
public function sendBody(ResponseInterface $response)
    {
        $range = $this->getContentRange($response->getHeaderLine('content-range'));

        $maxBufferLength = $this->getMaxBufferLength() ?: 8192;

        if ($range === false) {
            $body = $response->getBody();

            if ($body->isSeekable()) {
                $body->rewind();
            }

            while (!$body->eof()) {
                echo $body->read($maxBufferLength);

                $this->delay();
            }

            return;
        }

        list($unit, $first, $last, $length) = array_values($range);

        ++$last;

        $body = $response->getBody();
        $body->seek($first);
        $position = $first;

        while (!$body->eof() && $position < $last) {
            // The latest part
            if (($position + $maxBufferLength) > $last) {
                echo $body->read($last - $position);

                $this->delay();

                break;
            }

            echo $body->read($maxBufferLength);

            $position = $body->tell();

            $this->delay();
        }
    }
194062
public function respond(ResponseInterface $response)
    {
        $this->httpClient->respond(
            $response->getStatusCode(),
            $response->getBody()->__toString(),
            $response->getHeaders()
        );
    }
886165
protected function send(
        ResponseInterface $response,
        string $body): ResponseInterface
    {
        if (!$body) {
            $response = $this->sendErrorDocument($response);
        }
        unset($this->errorDocument);
        $response = $response->withHeader(
            Response::HEADER_CONTENT_LENGTH,
            (string) strlen($body));
        header(Response::PROTOCOL
             . $response->getProtocolVersion() . " "
             . $response->getStatusCode() . " "
             . $response->getReasonPhrase());
        foreach ($response->getHeaders() as $key => $value) {
            header($key . ": " . implode("; ", $value));
        }
        $response->getBody()->write($body);
        return $response;
    }
478788
public function sendResponse(ResponseInterface $response)
    {
        $e = $this->getEvent();
        $e->setResponse($response);

        $e->getApplication()->getEventManager()->trigger(MvcEvent::EVENT_FINISH, $e);
        exit();
    }
25626
public function setRequestAllowance(RequestInterface $request, ResponseInterface $response)
    {
        $route = $this->getRoute($request);

        $remaining = $response->getHeader('X-RateLimit-Remaining');
        $reset     = $response->getHeader('X-RateLimit-Reset');
        if (empty($remaining) || empty($reset) || (int) $remaining[0] > 0) {
            return;
        }

        $this->redis->set($this->getKey($route.'.reset'), static::MAX_TTL, $reset[0]);
    }
978334
public function respond( ResponseInterface $response ) {
		if ( ! headers_sent() ) {
			$this->sendHeaders( $response );
		}
		$this->sendBody( $response );
	}
646456
private function emitBody(ResponseInterface $response): void
    {
        $body = $response->getBody();

        if ($body->isSeekable()) {
            $body->rewind();
        }

        while (!$body->eof() && connection_status() === CONNECTION_NORMAL) {
            echo $body->read(self::CHUNK_SIZE);
        }
    }
380317
public static function setResponse(ResponseInterface $response)
    {
        $coroutineId = self::getCoroutineId();
        self::$context[$coroutineId][self::RESPONSE_KEY] = $response;
    }
569037
public function addCorsHeaders($response, $headers)
    {
        if (empty($headers) === false) {
            foreach ($headers as $field => $value) {
                $response->setHeader($field, $value);
            }
        }
    }
799176
private static function withCorsHeaders(ResponseInterface $response, array $headers): ResponseInterface
	{
		foreach ($headers as $name => $value) {
			$response = $response->withHeader($name, $value);
		}

		return $response;
	}
153558
public function leave(ResponseInterface $response = null)
    {
        $this->ends = [
            'wt' => microtime(true),
            'mu' => memory_get_usage(),
            'pmu' => memory_get_peak_usage(),
        ];
        if ($response) {
            $this->response = [
                'headers' => $response->getHeaders(),
                'statusCode' => $response->getStatusCode(),
                'body' => (string)$response->getBody(),
            ];
        }
    }
434345
protected function handleErrors(ResponseInterface $response)
    {
        $body = $response->getBody()->__toString();

        $content = json_decode($body, true);
        $message = '';
        if (JSON_ERROR_NONE === json_last_error()) {
            $message = $content['error'];
        }

        switch ($response->getStatusCode()) {
            case 401:
                throw new DomainExceptions\InvalidApiKeyException($message);
                break;
            case 403:
                throw new DomainExceptions\InsufficientPrivilegesException($message);
                break;
            case 404:
                throw new DomainExceptions\NotFoundException($message);
                break;

            default:
                throw new DomainExceptions\UnknownErrorException($message);
                break;
        }
    }