@param string $file
@param ResponseInterface $response

@return ResponseInterface
549160
public function onceResponse(string $file, ResponseInterface $response) : ResponseInterface
    {
        return $this->includeResponse('once', $file, $response);
    }
497377
protected function parseResponse(ResponseInterface $response)
    {
        $response = json_decode($response->getBody()->getContents());

        if (isset($response->success) && $response->success) {
            return $response->data;
        }

        throw new \Exception($response->error_info, $response->error_code);
    }
1341374
public function prepareCache(ResponseInterface $response)
    {
        /** @var MessageInterface|ResponseInterface $response */

        // Force cachable
        if ($this->getCachable() === static::CACHE_ENABLE) {
            // Expires.
            $response = $response->withoutHeader('Expires')->withHeader(
                'Expires',
                gmdate('D, d M Y H:i:s', time() + 900) . ' GMT'
            );

            // Last modified.
            if ($this->modifiedDate instanceof \DateTime) {
                $this->modifiedDate->setTimezone(new \DateTimeZone('UTC'));

                $response = $response->withoutHeader('Last-Modified')->withHeader(
                    'Last-Modified',
                    $this->modifiedDate->format('D, d M Y H:i:s') . ' GMT'
                );
            }
        } elseif ($this->getCachable() === static::CACHE_DISABLE) {
            // Force uncachable

            // Expires in the past.
            $response = $response->withoutHeader('Expires')->withHeader('Expires', 'Mon, 1 Jan 2001 00:00:00 GMT');

            // Always modified.
            $response = $response->withoutHeader('Last-Modified')->withHeader(
                'Last-Modified',
                gmdate('D, d M Y H:i:s') . ' GMT'
            );
            $response = $response->withoutHeader('Cache-Control')->withHeader(
                'Cache-Control',
                'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
            );

            // HTTP 1.0
            $response = $response->withHeader('pragma', 'no-cache');
        }

        return $response;
    }
163340
private function handleRedirect(ResponseInterface $response): ResponseInterface
    {
        if ($this->debugbar->isDataPersisted() || session_status() === PHP_SESSION_ACTIVE) {
            $this->debugbar->stackData();
        }

        return $response;
    }
922057
protected function getBodyContent(ResponseInterface $response)
    {
        $body    = $response->getBody();
        $headers = $response->getHeaders();

        return $this->createContent($headers, $body);
    }
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;
    }
951228
public function execute(ResponseInterface $response): ResponseInterface
    {
        if ($response->getStatusCode() === self::STATUS_CODE_OK) {
            if (is_null($this->publicKeyServer)) {
                // No installation yet.
                return $response;
            } else {
                $toVerify =
                    $response->getStatusCode() .
                    self::NEWLINE .
                    $this->determineHeaderStringForSignedResponse($response->getHeaders()) .
                    self::NEWLINE . self::NEWLINE .
                    $response->getBody()->getContents();

                $signature = base64_decode($response->getHeaderLine(self::HEADER_SERVER_SIGNATURE));
                $publicKey = $this->publicKeyServer->getKey();

                $signatureResult = openssl_verify($toVerify, $signature, $publicKey, OPENSSL_ALGO_SHA256);

                if ($signatureResult === self::RESULT_SIGNATURE_CORRECT) {
                    return $response;
                } else {
                    throw new SecurityException(self::ERROR_VERIFYING_RESPONSE_FAILED);
                }
            }
        } else {
            return $response;
        }
    }
927784
protected function finalizeResponse(ResponseInterface $response) : ResponseInterface
    {
        // stop PHP sending a Content-Type automatically
        ini_set('default_mimetype', '');
        if ($this->isEmptyResponseCode($response->getStatusCode())) {
            return $response->withoutHeader('Content-Type')->withoutHeader('Content-Length');
        }

        return $response;
    }
616333
private function attachNocacheCacheLimiterHeader(ResponseInterface $response): ResponseInterface
    {
        return $response
            ->withAddedHeader('Expires', self::EXPIRED)
            ->withAddedHeader('Cache-Control', 'no-store, no-cache, must-revalidate')
            ->withAddedHeader('Pragma', 'no-cache');
    }
380317
public static function setResponse(ResponseInterface $response)
    {
        $coroutineId = self::getCoroutineId();
        self::$context[$coroutineId][self::RESPONSE_KEY] = $response;
    }
1065801
protected function addHeaders(ResponseInterface $response, string $body): ResponseInterface
    {
        return $response
            ->andHeader('Content-Type', 'application/json')
            ->andHeader('Content-Length', (string)strlen($body));
    }
173872
public static function prepareAttachmentHeaders(
        ResponseInterface $response,
        ?string $filename = null
    ): ResponseInterface {
        $response = $response->withHeader('Content-Type', 'application/octet-stream')
            ->withHeader('Cache-Control', 'no-store, no-cache, must-revalidate')
            ->withHeader('Content-Transfer-Encoding', 'binary')
            ->withHeader('Content-Encoding', 'none');

        if ($filename !== null) {
            $response = $response->withHeader(
                'Content-Disposition',
                'attachment; filename*=utf-8\'\'' . rawurlencode($filename)
            );
        }

        return $response;
    }
1323219
public static function sendResponse(ResponseInterface $response)
    {
        header('HTTP/'.$response->getHttpVersion().' '.$response->getStatus().' '.$response->getStatusText());
        foreach ($response->getHeaders() as $key => $value) {
            foreach ($value as $k => $v) {
                if (0 === $k) {
                    header($key.': '.$v);
                } else {
                    header($key.': '.$v, false);
                }
            }
        }

        $body = $response->getBody();
        if (null === $body) {
            return;
        }

        if (is_callable($body)) {
            $body();

            return;
        }

        $contentLength = $response->getHeader('Content-Length');
        if (null !== $contentLength) {
            $output = fopen('php://output', 'wb');
            if (is_resource($body) && 'stream' == get_resource_type($body)) {
                if (PHP_INT_SIZE !== 4) {
                    // use the dedicated function on 64 Bit systems
                    stream_copy_to_stream($body, $output, (int) $contentLength);
                } else {
                    // workaround for 32 Bit systems to avoid stream_copy_to_stream
                    while (!feof($body)) {
                        fwrite($output, fread($body, 8192));
                    }
                }
            } else {
                fwrite($output, $body, (int) $contentLength);
            }
        } else {
            file_put_contents('php://output', $body);
        }

        if (is_resource($body)) {
            fclose($body);
        }
    }
760389
protected function parseResponse(ResponseInterface $response)
    {
        $content = (string) $response->getBody();

        if(strpos($content, "callback") !== false){
            $lpos = strpos($content, "(");
            $rpos = strrpos($content, ")");
            $content  = substr($content, $lpos + 1, $rpos - $lpos -1);

            return $this->parseJson($content);
        } else if(strpos($content, "access_token=") !== false) {
            $result = array();
            parse_str($content, $result);
            return $result;
        } else {
            return parent::parseResponse($response);
        }
    }
599820
protected function finalize(ResponseInterface $response)
    {
        // stop PHP sending a Content-Type automatically
        ini_set('default_mimetype', '');

        $request = $this->container->get('request');
        if ($this->isEmptyResponse($response) && !$this->isHeadRequest($request)) {
            return $response->withoutHeader('Content-Type')->withoutHeader('Content-Length');
        }

        // Add Content-Length header if `addContentLengthHeader` setting is set
        if (isset($this->container->get('settings')['addContentLengthHeader']) &&
            $this->container->get('settings')['addContentLengthHeader'] == true) {
            if (ob_get_length() > 0) {
                throw new RuntimeException("Unexpected data in output buffer. " .
                    "Maybe you have characters before an opening <?php tag?");
            }
            $size = $response->getBody()->getSize();
            if ($size !== null && !$response->hasHeader('Content-Length')) {
                $response = $response->withHeader('Content-Length', (string) $size);
            }
        }

        // clear the body if this is a HEAD request
        if ($this->isHeadRequest($request)) {
            return $response->withBody(new Body(fopen('php://temp', 'r+')));
        }

        return $response;
    }
1319594
protected function returnResponse(ResponseInterface $response): ResponseInterface
    {
        $this->nextHandler = null;
        reset($this->handlers);
        return $response;
    }
1292003
protected function mutateHeaders(ResponseInterface $response, File $file)
    {
        $response = $response->withHeader('Content-Type', 'application/force-download');
        $response = $response->withAddedHeader('Content-Type', 'application/octet-stream');
        $response = $response->withAddedHeader('Content-Type', 'application/download');

        $response = $response->withHeader('Content-Transfer-Encoding', 'binary');

        $response = $response->withHeader(
            'Content-Disposition',
            sprintf('attachment; filename="%s"', $file->base_name)
        );

        return $response;
    }