Yoast\WP\SEO\MyYoast_Client\Infrastructure\Http

HTTP_Client::get_cached_rate_limit_responseprivateYoast 1.0

Returns a cached 429 response with an updated Retry-After header, or null if not rate limited.

Метод класса: HTTP_Client{}

Хуков нет.

Возвращает

HTTP_Response|null. The cached response or null.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->get_cached_rate_limit_response( $url ): ?HTTP_Response;
$url(строка) (обязательный)
The request URL.

Код HTTP_Client::get_cached_rate_limit_response() Yoast 28.3

private function get_cached_rate_limit_response( string $url ): ?HTTP_Response {
	$key = $this->get_rate_limit_key( $url );

	try {
		$cached = $this->expiring_store->get( $key );
	} catch ( Key_Not_Found_Exception | Corrupted_Value_Exception $e ) {
		return null;
	}

	if ( ! \is_array( $cached ) || ! isset( $cached['stored_at'], $cached['backoff_seconds'], $cached['status'], $cached['headers'], $cached['body'] ) ) {
		return null;
	}

	$remaining = ( ( $cached['stored_at'] + $cached['backoff_seconds'] ) - \time() );
	if ( $remaining <= 0 ) {
		return null;
	}

	$headers                = $cached['headers'];
	$headers['retry-after'] = (string) $remaining;

	return new HTTP_Response( (int) $cached['status'], $headers, $cached['body'] );
}