Attach a session cache limiter header to the given response.

@param \Psr\Http\Message\ResponseInterface   $response
@param int                                   $time
@return \Psr\Http\Message\ResponseInterface
353781
private function attachCacheLimiterHeader(ResponseInterface $response, int $time): ResponseInterface
    {
        $cache_limiter = session_cache_limiter();

        switch ($cache_limiter) {
            case 'public':
                return $this->attachPublicCacheLimiterHeader($response, $time);
            case 'private':
                return $this->attachPrivateCacheLimiterHeader($response, $time);
            case 'private_no_expire':
                return $this->attachPrivateNoExpireCacheLimiterHeader($response, $time);
            case 'nocache':
                return $this->attachNocacheCacheLimiterHeader($response);
            default:
                return $response;
        }
    }
1022270
private function storeCachedResponse(Response $response, $method, $url, array $data, array $headers, $minutes)
    {
        if ($this->cache and $minutes > 0)
        {
            $this->cache->storeResponse($response, $method, $url, $data, $headers, $this->basicAuthCredentials, $minutes);
        }
    }
577301
protected function setHttpCache($response = null)
    {
        $http_cache_config = Lb::app()->getHttpCacheConfig();
        if (isset($http_cache_config['cache_control']) && isset($http_cache_config['offset'])) {
            HttpHelper::setCache($http_cache_config['cache_control'], $http_cache_config['offset'], $response);
        }
    }
382616
public function getCookie(ResponseInterface $response)
    {
        $result = null;
        $cookies = $response->getHeader('Set-Cookie');

        foreach ($cookies as $cookie) {
            if (strpos($cookie, 'SESSID') !== false) {
                $result = $cookie;
            }
        }
        return $result;
    }
688999
protected function encodeSetCookieHeader(ResponseInterface $response)
    {
        $cookies = CookieCollection::createFromHeader($response->getHeader('Set-Cookie'));
        $header = [];
        foreach ($cookies as $cookie) {
            if (in_array($cookie->getName(), $this->cookieNames, true)) {
                $value = $this->_encrypt($cookie->getValue(), $this->cipherType);
                $cookie = $cookie->withValue($value);
            }
            $header[] = $cookie->toHeaderValue();
        }

        return $response->withHeader('Set-Cookie', $header);
    }
879326
protected function configureResponse(ResponseInterface $Response){
        $Response->setRequest($this->Request);
        $Response->extract();
        return $Response;
    }
131435
protected function handleResponse(ResponseInterface $response): ResponseInterface
    {
        $contentType = $response->getHeader('Content-Type');

        if (in_array(self::CONTENT_TYPE_JSON_API, $contentType, true)) {
            $stream = $response->getBody();

            return new JsonApiResponse(
                $response->getStatusCode(),
                $response->getHeaders(),
                $this->streamToDocument($stream)
            );
        }

        return $response;
    }
1120780
private function injectHeaders(ResponseInterface $response, array $headers = []): ResponseInterface
    {
        foreach ($headers as $name => $value) {
            $response = $response->withHeader($name, $value);
        }

        return $response;
    }
495605
private function getTtl(ResponseInterface $response)
    {
        $ttl = 0;

        if ($cacheControl = $response->getHeader('Cache-Control')) {
            $maxAge = Utils::getDirective($response, 'max-age');
            if (is_numeric($maxAge)) {
                $ttl += $maxAge;
            }

            // According to RFC5861 stale headers are *in addition* to any
            // max-age values.
            $stale = Utils::getDirective($response, 'stale-if-error');
            if (is_numeric($stale)) {
                $ttl += $stale;
            }
        } elseif ($expires = $response->getHeader('Expires')) {
            $ttl += strtotime($expires) - time();
        }

        return $ttl ?: $this->defaultTtl;
    }
351119
private function processThrottleData(ResponseInterface $response)
    {
        if (empty($rateLimit = $response->getHeader('X-RateLimit-Limit'))) {
            return;
        }

        if (empty($remaining = $response->getHeader('X-RateLimit-Remaining'))) {
            return;
        }

        if (!empty($reset = $response->getHeader('X-RateLimit-Reset'))) {
            $this->rateLimit->setEndOfThrottle(intval($reset[0]));
        } else {
            $this->rateLimit->setEndOfThrottle(null);
        }

        $this->rateLimit->setMaxPerMinute(intval($rateLimit[0]))->setRemaining(intval($remaining[0]));
    }
34448
private void setDateAndCacheHeaders(final HttpResponse response) {
    final SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
    dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE));

    // Date header
    final Calendar time = new GregorianCalendar();
    response.headers().set(DATE, dateFormatter.format(time.getTime()));

    // Add cache headers
    time.add(Calendar.SECOND, HTTP_CACHE_SECONDS);
    response.headers().set(EXPIRES, dateFormatter.format(time.getTime()));
    response.headers().set(CACHE_CONTROL, "private, max-age=" + HTTP_CACHE_SECONDS);
    response.headers().set(LAST_MODIFIED, dateFormatter.format(new Date(startupTime)));
  }
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();
        }
    }
1319594
protected function returnResponse(ResponseInterface $response): ResponseInterface
    {
        $this->nextHandler = null;
        reset($this->handlers);
        return $response;
    }
838465
protected function listResponseHeaders(ResponseInterface $response):\Generator
    {
        foreach ($response->getHeaders() as $header => $values) {
            foreach ($values as $value) {
                yield $header => $value;
            }
        }
    }
907068
public function addFromResponse(ResponseInterface $response, RequestInterface $request)
    {
        $uri = $request->getUri();
        $host = $uri->getHost();
        $path = $uri->getPath() ?: '/';

        $cookies = static::parseSetCookieHeader($response->getHeader('Set-Cookie'));
        $cookies = $this->setRequestDefaults($cookies, $host, $path);
        $new = clone $this;
        foreach ($cookies as $cookie) {
            $new->cookies[$cookie->getId()] = $cookie;
        }
        $new->removeExpiredCookies($host, $path);

        return $new;
    }
34892
private static function range(ResponseInterface $response, string $range): ResponseInterface
    {
        $response = $response->withHeader('Accept-Ranges', 'bytes');

        if (empty($range) || !($range = self::parseRangeHeader($range))) {
            return $response;
        }

        list($first, $last) = $range;
        $size = $response->getBody()->getSize();

        if ($last === null) {
            $last = $size - 1;
        }

        return $response
            ->withStatus(206)
            ->withHeader('Content-Length', (string) ($last - $first + 1))
            ->withHeader('Content-Range', sprintf('bytes %d-%d/%d', $first, $last, $size));
    }
77991
protected function _setHeaders($response)
    {
        $headers = $this->getConfig('headers');

        if (!is_array($headers)) {
            return $response;
        }

        return $response
            ->withHeader($headers['limit'], (string)$this->getConfig('limit'))
            ->withHeader($headers['remaining'], (string)$this->_getRemainingConnections())
            ->withHeader(
                $headers['reset'],
                (string)Cache::read($this->_getCacheExpirationKey(), static::$cacheConfig)
            );
    }