Send the response the client

@param ResponseInterface $response
968477
public function serveResponse(ResponseInterface $response)
    {
        // add increment
        $this->servedResponseCount++;
        $allowServeEmpty = $this->getConfiguration('serveEmptyResponse') === true;
        $setContentLength = $this->getConfiguration('setContentLength') === true;
        // Send response
        if (!headers_sent()) {
            // Headers
            foreach ($response->getHeaders() as $name => $values) {
                if (!$setContentLength && strtolower($name) === 'content-length') {
                    continue;
                }

                foreach ($values as $value) {
                    header(sprintf('%s: %s', $name, $value), false);
                }
            }

            // Re Set Status Header
            header(sprintf(
                'HTTP/%s %s %s',
                $response->getProtocolVersion(),
                $response->getStatusCode(),
                $response->getReasonPhrase()
            ), true, $response->getStatusCode());
        }

        // Serve Response
        if ($allowServeEmpty || ! $this->isEmptyResponseCode($response->getStatusCode())) {
            $body = $response->getBody();
            if ($body->isSeekable()) {
                $body->rewind();
            }

            $chunkSize      = $this->getNormalizeResponseChunkSize();
            $contentLength  = $setContentLength
                ? $response->getHeaderLine('Content-Length')
                : null;

            if (!$contentLength) {
                $contentLength = $body->getSize();
                // set content length
                if ($setContentLength && !headers_sent()) {
                    header(sprintf('Content-Length: %d', $contentLength));
                }
            }

            // if use buffer create buffer
            $this->addCreateBuffer();
            if ($contentLength) {
                $amountToRead = $contentLength;
                while ($amountToRead > 0 && !$body->eof()) {
                    $data = $body->read(min($chunkSize, $amountToRead));
                    echo $data;
                    $amountToRead -= strlen($data);
                    if (connection_status() != CONNECTION_NORMAL) {
                        break;
                    }
                }
            } else {
                while (!$body->eof()) {
                    echo $body->read($chunkSize);
                    if (connection_status() != CONNECTION_NORMAL) {
                        break;
                    }
                }
            }
        }
    }
130303
protected function createLaravelResponse(ResponseInterface $response)
    {
        return new Response(
            (string) $response->getBody(),
            $response->getStatusCode(),
            $response->getHeaders()
        );
    }
35682
private function sendErrorDocument(
        ResponseInterface $response): ResponseInterface
        {
        if ($this->errorDocument && preg_match(
                "/^(4|5){1}[0-2]{1}[0-9]{1}$/", $response->getStatusCode())
            ) {
            $this->errorDocument = str_replace(
                "{status}", $response->getStatusCode(), $this->errorDocument
            );
            if ($this->errorDocument !== filter_input(INPUT_SERVER, "REQUEST_URI")) {
                $response = $response->withHeader(
                    Response::HEADER_REFRESH,
                    "0; " . $this->errorDocument
                );
            }
        }
        return $response;
    }
723503
protected function sendRequest(RequestInterface $request)
    {
        $response = $this->client->send($request);
        /* @var \Psr\Http\Message\ResponseInterface $response */

        return json_decode($response->getBody(), true);
    }
966521
public function sendBody(Response $response)
    {
        $body = $response->getBody();
        $body->rewind();
        echo $body->getContents();
        return $response;
    }
1184627
protected function sendHeaders(ResponseInterface $response): JsonRenderer
    {
        foreach ($response->getHeaders() as $header => $value) {
            if (is_array($value) === true) {
                $value = implode(', ', $value);
            }

            header(sprintf(
                '%s: %s',
                $header,
                $value
            ));
        }

        return $this;
    }
143759
public function output(\stdClass $object, ResponseInterface $response) {
        $response->setContentType('application/json');
        $response->setJsonContent($object);
        $response->send();
    }
680749
public function sendRequest(RequestInterface $request): ResponseInterface
    {
        $promise = $this->sendAsyncRequest($request);

        return $promise->wait();
    }
237233
private function fromPsrResponse(ResponseInterface $response)
    {
        return new Response(
            $response->getStatusCode(),
            $response->getHeaders(),
            $response->getBody(),
            $response->getProtocolVersion(),
            $response->getReasonPhrase()
        );
    }
194062
public function respond(ResponseInterface $response)
    {
        $this->httpClient->respond(
            $response->getStatusCode(),
            $response->getBody()->__toString(),
            $response->getHeaders()
        );
    }
15639
public function sendBody( ResponseInterface $response, $chunk_size = 4096 ) {
		$body = $this->getBody( $response );
		$content_length = $this->getBodyContentLength( $response );

		if ( $content_length > 0 ) {
			$this->sendBodyWithLength( $body, $content_length, $chunk_size );
		} else {
			$this->sendBodyWithoutLength( $body, $chunk_size );
		}
	}
1029283
protected function emitHttpStatus(ResponseInterface $response){
        $phrase = $response->getReasonPhrase();

        header(
            sprintf("HTTP/%s %d%s",
                $response->getProtocolVersion(),
                $response->getStatusCode(),
                "" === $phrase ? "" : " {$phrase}"
            )
        );
    }
211667
public function emit(ResponseInterface $response): bool
    {
        // Emit response (Headers + Status + Body)
        $this->emitHeaders($response);

        $range = $this->parseContentRange($response->getHeaderLine('Content-Range'));
        if (is_array($range) && $range[0] === 'bytes') {
            $this->emitBodyRange($range, $response, $this->maxBufferLength);
        } else {
            $this->emitBody($response, $this->maxBufferLength);
        }

        $this->closeConnexion();

        return true;
    }
121692
public function sendResponseBody(ResponseInterface $response):void
    {
        if (($body = $response->getBody()->detach()) === null) {
            $body = $response->getBody()->__toString();
        }
        $this->sendBody($body);
    }
897305
protected function handleTokenResponse(ResponseInterface $response)
    {
        $statusCode = $response->getStatusCode();
        if (500 <= $statusCode) {
            $e = new ServiceUnavailableException();
            $e->setResponse($response);
            throw $e;
        }

        $contentTypes = $response->getHeader('content-type');
        if (empty($contentTypes) || (0 !== strpos($contentTypes[0], 'application/json') && 0 !== strpos($contentTypes[0], 'text/javascript'))) {
            $e = new UnknownContentTypeException();
            $e->setResponse($response);
            if (!empty($contentTypes)) {
                $e->setContentType($contentTypes[0]);
            }
            throw $e;
        }

        $data = json_decode($response->getBody()->getContents(), true);
        if (200 !== $statusCode) {
            $e = new RequestTokenException();
            $e->setResponse($response);

            if (isset($data['error'])) {
                $e->setError(is_array($data['error']) ? json_encode($data['error']) : $data['error']);
            }

            if (isset($data['error_description'])) {
                $e->setDescription($data['error_description']);
            }

            if (isset($data['error_uri'])) {
                $e->setUri($data['error_uri']);
            }

            throw $e;
        }

        if (isset($data['access_token'])) {
            $this->setAccessToken($data['access_token']);
        }

        return $data;
    }
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
        ]));
    }
1196758
public function send(): ResponseInterface
    {
        $client = new HttpClient(['base_uri' => $this->url]);

        return $client->get(
            $this->getUrlPath(),
            [
                'query' => $this->getParams(),
            ]
        );
    }