WpOrgRequestsResponse

HTTP response object returned by Requests::request().

Source: wp-includes/Requests/src/Response.php
Namespace: WpOrgRequests


Properties

PropertyTypeDefaultDescription
$bodystring''Response body
$rawstring''Raw HTTP data from the transport (headers + body)
$headersResponseHeaders(new Headers)Response headers as a case-insensitive dictionary
$status_codeint|boolfalseHTTP status code, false if non-blocking
$protocol_versionfloat|boolfalseHTTP protocol version (e.g. 1.1), false if non-blocking
$successboolfalseWhether the response is successful (2xx status)
$redirectsint0Number of redirects followed
$urlstring''Final requested URL
$historyarray[]Previous Response objects from redirects
$cookiesCookieJar(new Jar)Cookies from the response

Methods

__construct()

php
public function __construct()

Creates a new Response with fresh Headers and Jar instances.


is_redirect()

php
public function is_redirect(): bool

Check if the response is a redirect. Returns true for status codes 300, 301, 302, 303, 307, and 308–399.


throw_for_status()

php
public function throw_for_status( bool $allow_redirects = true ): void

Throws an exception if the request was not successful.

ParameterTypeDescription
$allow_redirectsboolSet to false to throw on 3xx responses

Throws:

  • Exception — If $allow_redirects is false and status is 3xx (response.no_redirects)
  • ExceptionHttpStatusXXX — On non-2xx, non-3xx status codes (class name matches status code)

decode_body()

php
public function decode_body( ?bool $associative = true, int $depth = 512, int $options = 0 ): array

JSON decode the response body. Parameters mirror PHP’s json_decode().

ParameterTypeDefaultDescription
$associativebool|nulltrueReturn associative arrays (default differs from PHP’s null)
$depthint512Maximum nesting depth
$optionsint0JSON decode bitmask flags

Returns: Decoded data.

Throws: Exception — If body is not valid JSON (response.invalid).