Yoast\WP\SEO\MyYoast_Client\Infrastructure\Http

HTTP_Client::do_request │ private │ Yoast 1.0

Executes a single HTTP request with optional DPoP proof injection.

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

Хуков нет.

Возвращает

HTTP_Response. The parsed response.

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

// private - только в коде основоного (родительского) класса
$result = $this->do_request( $method, $url, $options ): HTTP_Response;
$method(строка) (обязательный)
The HTTP method.
$url(строка) (обязательный)
The request URL.
$options(array<string, string|int|true|false|string[]|null>) (обязательный)
Request options.

Код HTTP_Client::do_request() Yoast 28.9

private function do_request( string $method, string $url, array $options ): HTTP_Response {
	$headers = ( $options['headers'] ?? [] );
	$timeout = ( $options['timeout'] ?? 10 );

	// Add DPoP proof header if requested.
	if ( ! empty( $options['dpop'] ) ) {
		$access_token = ( $options['access_token'] ?? null );
		try {
			$headers['DPoP'] = $this->dpop_handler->create_proof( $method, $url, $access_token );
		} catch ( DPoP_Proof_Exception $e ) {
			$this->logger->error(
				'DPoP proof generation failed for {method} {url}: {error}',
				[
					'method'                       => $method,
					'url'                          => $url,
					'error'                        => $e->getMessage(),
				],
			);
			return new HTTP_Response(
				0,
				[],
				[
					'error'             => 'dpop_proof_failed',
					'error_description' => $e->getMessage(),
				],
			);
		}
	}

	$wp_args = [
		'method'  => \strtoupper( $method ),
		'headers' => $headers,
		'timeout' => $timeout,
	];

	if ( isset( $options['body'] ) ) {
		$wp_args['body'] = $options['body'];
	}

	$response = \wp_remote_request( $url, $wp_args );

	return $this->parse_response( $response, $url );
}