Check if user hit limit.

@param ResponseInterface $response
326986
private function checkUserRateLimit(ResponseInterface $response)
    {
        $userRemaining = $response->getHeaderLine('X-RateLimit-UserRemaining');
        $userLimit = $response->getHeaderLine('X-RateLimit-UserLimit');

        if ('' !== $userRemaining && $userRemaining < 1) {
            throw new RateLimitException('No user credits available. The limit is ' . $userLimit);
        }
    }
755756
public function save(ResponseInterface $response)
    {
        $this->setStatusCode($response->getStatusCode());
        $this->setStatusPhrase($response->getReasonPhrase());
        $this->setBody($response->getBody()->getContents());

        // rewind to previous position after reading response body
        if ($response->getBody()->isSeekable()) {
            $response->getBody()->rewind();
        }

        $this->setHeaders($response->getHeaders());
        $this->setProtocolVersion($response->getProtocolVersion());
    }
917732
private function shouldSendDataOnNextPage(ResponseInterface $response): bool
    {
        $status_code = $response->getStatusCode();

        return $status_code === self::STATUS_FOUND || $status_code === self::STATUS_MOVED_PERMANENTLY;
    }
911597
private static function checkResponse(Response $response)
    {
        $statusCode = $response->getStatusCode();

        if ($statusCode >= 400 && $statusCode < 600) {
            $reason = $response->getReasonPhrase();
            $body = json_decode($response->getBody());

            if (isset($body->error->exception[0]->message)) {
                $reason = $body->error->exception[0]->message;
            }

            throw new FenrirApiException($statusCode, $reason);
        }
    }
194062
public function respond(ResponseInterface $response)
    {
        $this->httpClient->respond(
            $response->getStatusCode(),
            $response->getBody()->__toString(),
            $response->getHeaders()
        );
    }
783843
public static function sendResponse(ResponseInterface $response) 
    {
		$code = $response->getStatusCode();
		$reason = $response->getReasonPhrase();
		header(
			sprintf('HTTP/%s %s %s', $response->getProtocolVersion(), $code, $reason),
			true, $code 
		);

		foreach ($response->getHeaders() as $header => $values) {
			foreach ($values as $value) {
				header("$header: $value", false);
			}
		}

		echo $response->getBody();
	}
1212034
private function checkCacheControl(ResponseInterface $response)
    {
        $cacheControl = $response->getHeaderLine('Cache-Control');
        $vals = array_map('trim', explode(',', $cacheControl));
        $fullURL = Controller::join_links(Director::absoluteBaseURL(), $this->url);

        // All entries from must contain should be present
        if ($this->mustInclude == array_intersect($this->mustInclude, $vals)) {
            $matched = implode(",", $this->mustInclude);
            $this->result->addMessage(
                "$fullURL includes all settings: {$matched}",
                ValidationResult::TYPE_GOOD
            );
        } else {
            $missing = implode(",", array_diff($this->mustInclude, $vals));
            $this->result->addError(
                "$fullURL is excluding some settings: {$missing}"
            );
        }

        // All entries from must exclude should not be present
        if (empty(array_intersect($this->mustExclude, $vals))) {
            $missing = implode(",", $this->mustExclude);
            $this->result->addMessage(
                "$fullURL excludes all settings: {$missing}",
                ValidationResult::TYPE_GOOD
            );
        } else {
            $matched = implode(",", array_intersect($this->mustExclude, $vals));
            $this->result->addError(
                "$fullURL is including some settings: {$matched}"
            );
        }
    }
722507
private function shareExceptionTrace(ResponseInterface $response): void
    {
        foreach ($response->getExceptions() as $exception) {
            if ($exception instanceof GraphQLExceptionInterface) {
                $exception->withExtension(new ExceptionTraceExtension($exception));
            }

            $exception->publish();
        }
    }
1288259
private function checkClientRateLimit(ResponseInterface $response)
    {
        $clientRemaining = $response->getHeaderLine('X-RateLimit-ClientRemaining');
        $clientLimit = $response->getHeaderLine('X-RateLimit-ClientLimit');

        if ('' !== $clientRemaining && $clientRemaining < 1) {
            // X-RateLimit-UserReset: Timestamp (unix epoch) for when the credits will be reset.
            $resetTime = date('Y-m-d H:i:s', $response->getHeaderLine('X-RateLimit-UserReset'));

            throw new RateLimitException('No application credits available. The limit is ' . $clientLimit . ' and will be reset at ' . $resetTime);
        }
    }
282328
protected function getBodyContentLength( ResponseInterface $response ) {
		$content_length = $response->getHeaderLine( 'Content-Length' );

		if ( ! $content_length ) {
			$body = $this->getBody( $response );
			$content_length = $body->getSize();
		}

		if ( ! is_numeric( $content_length ) ) {
			$content_length = 0;
		}

		return (integer) $content_length;
	}
204770
public function intercept(ResponseInterface $response)
    {
        $this->stopPropagation();
        $this->getTransaction()->setResponse($response);
        $this->exception->setThrowImmediately(false);
        RequestEvents::emitComplete($this->getTransaction());
    }
1332088
public function sendHeaders( ResponseInterface $response ) {
		// Status
		header( sprintf(
			'HTTP/%s %s %s',
			$response->getProtocolVersion(),
			$response->getStatusCode(),
			$response->getReasonPhrase()
		) );

		// Headers
		foreach ( $response->getHeaders() as $name => $values ) {
			foreach ( $values as $value ) {
				header( sprintf( '%s: %s', $name, $value ), false );
			}
		}
	}
1089584
private function isSuccessful(Response $response): bool
    {
        if ($response->statusCode()->value() !== 200) {
            return false;
        }

        $json = Json::decode((string) $response->body());

        return count($json['errors']) === 0;
    }
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;
    }
950680
protected function emitResponse(ResponseInterface $response) {
        $this->logger->flush();
        (new \Zend\HttpHandlerRunner\Emitter\SapiEmitter())->emit($response);
    }
1196616
public function processFiltersStack(ResponseInterface $response)
    {
        if (!$this->hasFilters()) {
            return true;
        }

        foreach ($this->filters as $filter) {
            if ($filter->isIncluded($response)) {
                return true;
            }
        }

        return false;
    }
269482
protected function checkErrorResponse(ResponseInterface $response)
    {
        $statusCode = $response->getStatusCode();
        if (200 <= $statusCode && $statusCode < 299) {
            if (!$response->getBody()->getSize()) {
                throw new BadResponseException('unexpected empty body');
            }

            return;
        }

        // Mitake API always return status code 200
        throw new BadResponseException(sprintf('unexpected status code: %d', $statusCode));
    }