Edit File by line
/home/barbar84/public_h.../wp-inclu...
File: class-http.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* HTTP API: WP_Http class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage HTTP
[5] Fix | Delete
* @since 2.7.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
if ( ! class_exists( 'Requests' ) ) {
[9] Fix | Delete
require ABSPATH . WPINC . '/class-requests.php';
[10] Fix | Delete
[11] Fix | Delete
Requests::register_autoloader();
[12] Fix | Delete
Requests::set_certificate_path( ABSPATH . WPINC . '/certificates/ca-bundle.crt' );
[13] Fix | Delete
}
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* Core class used for managing HTTP transports and making HTTP requests.
[17] Fix | Delete
*
[18] Fix | Delete
* This class is used to consistently make outgoing HTTP requests easy for developers
[19] Fix | Delete
* while still being compatible with the many PHP configurations under which
[20] Fix | Delete
* WordPress runs.
[21] Fix | Delete
*
[22] Fix | Delete
* Debugging includes several actions, which pass different variables for debugging the HTTP API.
[23] Fix | Delete
*
[24] Fix | Delete
* @since 2.7.0
[25] Fix | Delete
*/
[26] Fix | Delete
class WP_Http {
[27] Fix | Delete
[28] Fix | Delete
// Aliases for HTTP response codes.
[29] Fix | Delete
const HTTP_CONTINUE = 100;
[30] Fix | Delete
const SWITCHING_PROTOCOLS = 101;
[31] Fix | Delete
const PROCESSING = 102;
[32] Fix | Delete
const EARLY_HINTS = 103;
[33] Fix | Delete
[34] Fix | Delete
const OK = 200;
[35] Fix | Delete
const CREATED = 201;
[36] Fix | Delete
const ACCEPTED = 202;
[37] Fix | Delete
const NON_AUTHORITATIVE_INFORMATION = 203;
[38] Fix | Delete
const NO_CONTENT = 204;
[39] Fix | Delete
const RESET_CONTENT = 205;
[40] Fix | Delete
const PARTIAL_CONTENT = 206;
[41] Fix | Delete
const MULTI_STATUS = 207;
[42] Fix | Delete
const IM_USED = 226;
[43] Fix | Delete
[44] Fix | Delete
const MULTIPLE_CHOICES = 300;
[45] Fix | Delete
const MOVED_PERMANENTLY = 301;
[46] Fix | Delete
const FOUND = 302;
[47] Fix | Delete
const SEE_OTHER = 303;
[48] Fix | Delete
const NOT_MODIFIED = 304;
[49] Fix | Delete
const USE_PROXY = 305;
[50] Fix | Delete
const RESERVED = 306;
[51] Fix | Delete
const TEMPORARY_REDIRECT = 307;
[52] Fix | Delete
const PERMANENT_REDIRECT = 308;
[53] Fix | Delete
[54] Fix | Delete
const BAD_REQUEST = 400;
[55] Fix | Delete
const UNAUTHORIZED = 401;
[56] Fix | Delete
const PAYMENT_REQUIRED = 402;
[57] Fix | Delete
const FORBIDDEN = 403;
[58] Fix | Delete
const NOT_FOUND = 404;
[59] Fix | Delete
const METHOD_NOT_ALLOWED = 405;
[60] Fix | Delete
const NOT_ACCEPTABLE = 406;
[61] Fix | Delete
const PROXY_AUTHENTICATION_REQUIRED = 407;
[62] Fix | Delete
const REQUEST_TIMEOUT = 408;
[63] Fix | Delete
const CONFLICT = 409;
[64] Fix | Delete
const GONE = 410;
[65] Fix | Delete
const LENGTH_REQUIRED = 411;
[66] Fix | Delete
const PRECONDITION_FAILED = 412;
[67] Fix | Delete
const REQUEST_ENTITY_TOO_LARGE = 413;
[68] Fix | Delete
const REQUEST_URI_TOO_LONG = 414;
[69] Fix | Delete
const UNSUPPORTED_MEDIA_TYPE = 415;
[70] Fix | Delete
const REQUESTED_RANGE_NOT_SATISFIABLE = 416;
[71] Fix | Delete
const EXPECTATION_FAILED = 417;
[72] Fix | Delete
const IM_A_TEAPOT = 418;
[73] Fix | Delete
const MISDIRECTED_REQUEST = 421;
[74] Fix | Delete
const UNPROCESSABLE_ENTITY = 422;
[75] Fix | Delete
const LOCKED = 423;
[76] Fix | Delete
const FAILED_DEPENDENCY = 424;
[77] Fix | Delete
const UPGRADE_REQUIRED = 426;
[78] Fix | Delete
const PRECONDITION_REQUIRED = 428;
[79] Fix | Delete
const TOO_MANY_REQUESTS = 429;
[80] Fix | Delete
const REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
[81] Fix | Delete
const UNAVAILABLE_FOR_LEGAL_REASONS = 451;
[82] Fix | Delete
[83] Fix | Delete
const INTERNAL_SERVER_ERROR = 500;
[84] Fix | Delete
const NOT_IMPLEMENTED = 501;
[85] Fix | Delete
const BAD_GATEWAY = 502;
[86] Fix | Delete
const SERVICE_UNAVAILABLE = 503;
[87] Fix | Delete
const GATEWAY_TIMEOUT = 504;
[88] Fix | Delete
const HTTP_VERSION_NOT_SUPPORTED = 505;
[89] Fix | Delete
const VARIANT_ALSO_NEGOTIATES = 506;
[90] Fix | Delete
const INSUFFICIENT_STORAGE = 507;
[91] Fix | Delete
const NOT_EXTENDED = 510;
[92] Fix | Delete
const NETWORK_AUTHENTICATION_REQUIRED = 511;
[93] Fix | Delete
[94] Fix | Delete
/**
[95] Fix | Delete
* Send an HTTP request to a URI.
[96] Fix | Delete
*
[97] Fix | Delete
* Please note: The only URI that are supported in the HTTP Transport implementation
[98] Fix | Delete
* are the HTTP and HTTPS protocols.
[99] Fix | Delete
*
[100] Fix | Delete
* @since 2.7.0
[101] Fix | Delete
*
[102] Fix | Delete
* @param string $url The request URL.
[103] Fix | Delete
* @param string|array $args {
[104] Fix | Delete
* Optional. Array or string of HTTP request arguments.
[105] Fix | Delete
*
[106] Fix | Delete
* @type string $method Request method. Accepts 'GET', 'POST', 'HEAD', 'PUT', 'DELETE',
[107] Fix | Delete
* 'TRACE', 'OPTIONS', or 'PATCH'.
[108] Fix | Delete
* Some transports technically allow others, but should not be
[109] Fix | Delete
* assumed. Default 'GET'.
[110] Fix | Delete
* @type float $timeout How long the connection should stay open in seconds. Default 5.
[111] Fix | Delete
* @type int $redirection Number of allowed redirects. Not supported by all transports
[112] Fix | Delete
* Default 5.
[113] Fix | Delete
* @type string $httpversion Version of the HTTP protocol to use. Accepts '1.0' and '1.1'.
[114] Fix | Delete
* Default '1.0'.
[115] Fix | Delete
* @type string $user-agent User-agent value sent.
[116] Fix | Delete
* Default 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ).
[117] Fix | Delete
* @type bool $reject_unsafe_urls Whether to pass URLs through wp_http_validate_url().
[118] Fix | Delete
* Default false.
[119] Fix | Delete
* @type bool $blocking Whether the calling code requires the result of the request.
[120] Fix | Delete
* If set to false, the request will be sent to the remote server,
[121] Fix | Delete
* and processing returned to the calling code immediately, the caller
[122] Fix | Delete
* will know if the request succeeded or failed, but will not receive
[123] Fix | Delete
* any response from the remote server. Default true.
[124] Fix | Delete
* @type string|array $headers Array or string of headers to send with the request.
[125] Fix | Delete
* Default empty array.
[126] Fix | Delete
* @type array $cookies List of cookies to send with the request. Default empty array.
[127] Fix | Delete
* @type string|array $body Body to send with the request. Default null.
[128] Fix | Delete
* @type bool $compress Whether to compress the $body when sending the request.
[129] Fix | Delete
* Default false.
[130] Fix | Delete
* @type bool $decompress Whether to decompress a compressed response. If set to false and
[131] Fix | Delete
* compressed content is returned in the response anyway, it will
[132] Fix | Delete
* need to be separately decompressed. Default true.
[133] Fix | Delete
* @type bool $sslverify Whether to verify SSL for the request. Default true.
[134] Fix | Delete
* @type string $sslcertificates Absolute path to an SSL certificate .crt file.
[135] Fix | Delete
* Default ABSPATH . WPINC . '/certificates/ca-bundle.crt'.
[136] Fix | Delete
* @type bool $stream Whether to stream to a file. If set to true and no filename was
[137] Fix | Delete
* given, it will be droped it in the WP temp dir and its name will
[138] Fix | Delete
* be set using the basename of the URL. Default false.
[139] Fix | Delete
* @type string $filename Filename of the file to write to when streaming. $stream must be
[140] Fix | Delete
* set to true. Default null.
[141] Fix | Delete
* @type int $limit_response_size Size in bytes to limit the response to. Default null.
[142] Fix | Delete
*
[143] Fix | Delete
* }
[144] Fix | Delete
* @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'.
[145] Fix | Delete
* A WP_Error instance upon error.
[146] Fix | Delete
*/
[147] Fix | Delete
public function request( $url, $args = array() ) {
[148] Fix | Delete
$defaults = array(
[149] Fix | Delete
'method' => 'GET',
[150] Fix | Delete
/**
[151] Fix | Delete
* Filters the timeout value for an HTTP request.
[152] Fix | Delete
*
[153] Fix | Delete
* @since 2.7.0
[154] Fix | Delete
* @since 5.1.0 The `$url` parameter was added.
[155] Fix | Delete
*
[156] Fix | Delete
* @param float $timeout_value Time in seconds until a request times out. Default 5.
[157] Fix | Delete
* @param string $url The request URL.
[158] Fix | Delete
*/
[159] Fix | Delete
'timeout' => apply_filters( 'http_request_timeout', 5, $url ),
[160] Fix | Delete
/**
[161] Fix | Delete
* Filters the number of redirects allowed during an HTTP request.
[162] Fix | Delete
*
[163] Fix | Delete
* @since 2.7.0
[164] Fix | Delete
* @since 5.1.0 The `$url` parameter was added.
[165] Fix | Delete
*
[166] Fix | Delete
* @param int $redirect_count Number of redirects allowed. Default 5.
[167] Fix | Delete
* @param string $url The request URL.
[168] Fix | Delete
*/
[169] Fix | Delete
'redirection' => apply_filters( 'http_request_redirection_count', 5, $url ),
[170] Fix | Delete
/**
[171] Fix | Delete
* Filters the version of the HTTP protocol used in a request.
[172] Fix | Delete
*
[173] Fix | Delete
* @since 2.7.0
[174] Fix | Delete
* @since 5.1.0 The `$url` parameter was added.
[175] Fix | Delete
*
[176] Fix | Delete
* @param string $version Version of HTTP used. Accepts '1.0' and '1.1'. Default '1.0'.
[177] Fix | Delete
* @param string $url The request URL.
[178] Fix | Delete
*/
[179] Fix | Delete
'httpversion' => apply_filters( 'http_request_version', '1.0', $url ),
[180] Fix | Delete
/**
[181] Fix | Delete
* Filters the user agent value sent with an HTTP request.
[182] Fix | Delete
*
[183] Fix | Delete
* @since 2.7.0
[184] Fix | Delete
* @since 5.1.0 The `$url` parameter was added.
[185] Fix | Delete
*
[186] Fix | Delete
* @param string $user_agent WordPress user agent string.
[187] Fix | Delete
* @param string $url The request URL.
[188] Fix | Delete
*/
[189] Fix | Delete
'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . get_bloginfo( 'version' ) . '; ' . get_bloginfo( 'url' ), $url ),
[190] Fix | Delete
/**
[191] Fix | Delete
* Filters whether to pass URLs through wp_http_validate_url() in an HTTP request.
[192] Fix | Delete
*
[193] Fix | Delete
* @since 3.6.0
[194] Fix | Delete
* @since 5.1.0 The `$url` parameter was added.
[195] Fix | Delete
*
[196] Fix | Delete
* @param bool $pass_url Whether to pass URLs through wp_http_validate_url(). Default false.
[197] Fix | Delete
* @param string $url The request URL.
[198] Fix | Delete
*/
[199] Fix | Delete
'reject_unsafe_urls' => apply_filters( 'http_request_reject_unsafe_urls', false, $url ),
[200] Fix | Delete
'blocking' => true,
[201] Fix | Delete
'headers' => array(),
[202] Fix | Delete
'cookies' => array(),
[203] Fix | Delete
'body' => null,
[204] Fix | Delete
'compress' => false,
[205] Fix | Delete
'decompress' => true,
[206] Fix | Delete
'sslverify' => true,
[207] Fix | Delete
'sslcertificates' => ABSPATH . WPINC . '/certificates/ca-bundle.crt',
[208] Fix | Delete
'stream' => false,
[209] Fix | Delete
'filename' => null,
[210] Fix | Delete
'limit_response_size' => null,
[211] Fix | Delete
);
[212] Fix | Delete
[213] Fix | Delete
// Pre-parse for the HEAD checks.
[214] Fix | Delete
$args = wp_parse_args( $args );
[215] Fix | Delete
[216] Fix | Delete
// By default, HEAD requests do not cause redirections.
[217] Fix | Delete
if ( isset( $args['method'] ) && 'HEAD' === $args['method'] ) {
[218] Fix | Delete
$defaults['redirection'] = 0;
[219] Fix | Delete
}
[220] Fix | Delete
[221] Fix | Delete
$parsed_args = wp_parse_args( $args, $defaults );
[222] Fix | Delete
/**
[223] Fix | Delete
* Filters the arguments used in an HTTP request.
[224] Fix | Delete
*
[225] Fix | Delete
* @since 2.7.0
[226] Fix | Delete
*
[227] Fix | Delete
* @param array $parsed_args An array of HTTP request arguments.
[228] Fix | Delete
* @param string $url The request URL.
[229] Fix | Delete
*/
[230] Fix | Delete
$parsed_args = apply_filters( 'http_request_args', $parsed_args, $url );
[231] Fix | Delete
[232] Fix | Delete
// The transports decrement this, store a copy of the original value for loop purposes.
[233] Fix | Delete
if ( ! isset( $parsed_args['_redirection'] ) ) {
[234] Fix | Delete
$parsed_args['_redirection'] = $parsed_args['redirection'];
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
/**
[238] Fix | Delete
* Filters the preemptive return value of an HTTP request.
[239] Fix | Delete
*
[240] Fix | Delete
* Returning a non-false value from the filter will short-circuit the HTTP request and return
[241] Fix | Delete
* early with that value. A filter should return one of:
[242] Fix | Delete
*
[243] Fix | Delete
* - An array containing 'headers', 'body', 'response', 'cookies', and 'filename' elements
[244] Fix | Delete
* - A WP_Error instance
[245] Fix | Delete
* - boolean false to avoid short-circuiting the response
[246] Fix | Delete
*
[247] Fix | Delete
* Returning any other value may result in unexpected behaviour.
[248] Fix | Delete
*
[249] Fix | Delete
* @since 2.9.0
[250] Fix | Delete
*
[251] Fix | Delete
* @param false|array|WP_Error $preempt A preemptive return value of an HTTP request. Default false.
[252] Fix | Delete
* @param array $parsed_args HTTP request arguments.
[253] Fix | Delete
* @param string $url The request URL.
[254] Fix | Delete
*/
[255] Fix | Delete
$pre = apply_filters( 'pre_http_request', false, $parsed_args, $url );
[256] Fix | Delete
[257] Fix | Delete
if ( false !== $pre ) {
[258] Fix | Delete
return $pre;
[259] Fix | Delete
}
[260] Fix | Delete
[261] Fix | Delete
if ( function_exists( 'wp_kses_bad_protocol' ) ) {
[262] Fix | Delete
if ( $parsed_args['reject_unsafe_urls'] ) {
[263] Fix | Delete
$url = wp_http_validate_url( $url );
[264] Fix | Delete
}
[265] Fix | Delete
if ( $url ) {
[266] Fix | Delete
$url = wp_kses_bad_protocol( $url, array( 'http', 'https', 'ssl' ) );
[267] Fix | Delete
}
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
$arrURL = parse_url( $url );
[271] Fix | Delete
[272] Fix | Delete
if ( empty( $url ) || empty( $arrURL['scheme'] ) ) {
[273] Fix | Delete
$response = new WP_Error( 'http_request_failed', __( 'A valid URL was not provided.' ) );
[274] Fix | Delete
/** This action is documented in wp-includes/class-http.php */
[275] Fix | Delete
do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
[276] Fix | Delete
return $response;
[277] Fix | Delete
}
[278] Fix | Delete
[279] Fix | Delete
if ( $this->block_request( $url ) ) {
[280] Fix | Delete
$response = new WP_Error( 'http_request_not_executed', __( 'User has blocked requests through HTTP.' ) );
[281] Fix | Delete
/** This action is documented in wp-includes/class-http.php */
[282] Fix | Delete
do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
[283] Fix | Delete
return $response;
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
// If we are streaming to a file but no filename was given drop it in the WP temp dir
[287] Fix | Delete
// and pick its name using the basename of the $url.
[288] Fix | Delete
if ( $parsed_args['stream'] ) {
[289] Fix | Delete
if ( empty( $parsed_args['filename'] ) ) {
[290] Fix | Delete
$parsed_args['filename'] = get_temp_dir() . basename( $url );
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
// Force some settings if we are streaming to a file and check for existence
[294] Fix | Delete
// and perms of destination directory.
[295] Fix | Delete
$parsed_args['blocking'] = true;
[296] Fix | Delete
if ( ! wp_is_writable( dirname( $parsed_args['filename'] ) ) ) {
[297] Fix | Delete
$response = new WP_Error( 'http_request_failed', __( 'Destination directory for file streaming does not exist or is not writable.' ) );
[298] Fix | Delete
/** This action is documented in wp-includes/class-http.php */
[299] Fix | Delete
do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
[300] Fix | Delete
return $response;
[301] Fix | Delete
}
[302] Fix | Delete
}
[303] Fix | Delete
[304] Fix | Delete
if ( is_null( $parsed_args['headers'] ) ) {
[305] Fix | Delete
$parsed_args['headers'] = array();
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
// WP allows passing in headers as a string, weirdly.
[309] Fix | Delete
if ( ! is_array( $parsed_args['headers'] ) ) {
[310] Fix | Delete
$processedHeaders = WP_Http::processHeaders( $parsed_args['headers'] );
[311] Fix | Delete
$parsed_args['headers'] = $processedHeaders['headers'];
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
// Setup arguments.
[315] Fix | Delete
$headers = $parsed_args['headers'];
[316] Fix | Delete
$data = $parsed_args['body'];
[317] Fix | Delete
$type = $parsed_args['method'];
[318] Fix | Delete
$options = array(
[319] Fix | Delete
'timeout' => $parsed_args['timeout'],
[320] Fix | Delete
'useragent' => $parsed_args['user-agent'],
[321] Fix | Delete
'blocking' => $parsed_args['blocking'],
[322] Fix | Delete
'hooks' => new WP_HTTP_Requests_Hooks( $url, $parsed_args ),
[323] Fix | Delete
);
[324] Fix | Delete
[325] Fix | Delete
// Ensure redirects follow browser behaviour.
[326] Fix | Delete
$options['hooks']->register( 'requests.before_redirect', array( get_class(), 'browser_redirect_compatibility' ) );
[327] Fix | Delete
[328] Fix | Delete
// Validate redirected URLs.
[329] Fix | Delete
if ( function_exists( 'wp_kses_bad_protocol' ) && $parsed_args['reject_unsafe_urls'] ) {
[330] Fix | Delete
$options['hooks']->register( 'requests.before_redirect', array( get_class(), 'validate_redirects' ) );
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
if ( $parsed_args['stream'] ) {
[334] Fix | Delete
$options['filename'] = $parsed_args['filename'];
[335] Fix | Delete
}
[336] Fix | Delete
if ( empty( $parsed_args['redirection'] ) ) {
[337] Fix | Delete
$options['follow_redirects'] = false;
[338] Fix | Delete
} else {
[339] Fix | Delete
$options['redirects'] = $parsed_args['redirection'];
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
// Use byte limit, if we can.
[343] Fix | Delete
if ( isset( $parsed_args['limit_response_size'] ) ) {
[344] Fix | Delete
$options['max_bytes'] = $parsed_args['limit_response_size'];
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
// If we've got cookies, use and convert them to Requests_Cookie.
[348] Fix | Delete
if ( ! empty( $parsed_args['cookies'] ) ) {
[349] Fix | Delete
$options['cookies'] = WP_Http::normalize_cookies( $parsed_args['cookies'] );
[350] Fix | Delete
}
[351] Fix | Delete
[352] Fix | Delete
// SSL certificate handling.
[353] Fix | Delete
if ( ! $parsed_args['sslverify'] ) {
[354] Fix | Delete
$options['verify'] = false;
[355] Fix | Delete
$options['verifyname'] = false;
[356] Fix | Delete
} else {
[357] Fix | Delete
$options['verify'] = $parsed_args['sslcertificates'];
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
// All non-GET/HEAD requests should put the arguments in the form body.
[361] Fix | Delete
if ( 'HEAD' !== $type && 'GET' !== $type ) {
[362] Fix | Delete
$options['data_format'] = 'body';
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
/**
[366] Fix | Delete
* Filters whether SSL should be verified for non-local requests.
[367] Fix | Delete
*
[368] Fix | Delete
* @since 2.8.0
[369] Fix | Delete
* @since 5.1.0 The `$url` parameter was added.
[370] Fix | Delete
*
[371] Fix | Delete
* @param bool $ssl_verify Whether to verify the SSL connection. Default true.
[372] Fix | Delete
* @param string $url The request URL.
[373] Fix | Delete
*/
[374] Fix | Delete
$options['verify'] = apply_filters( 'https_ssl_verify', $options['verify'], $url );
[375] Fix | Delete
[376] Fix | Delete
// Check for proxies.
[377] Fix | Delete
$proxy = new WP_HTTP_Proxy();
[378] Fix | Delete
if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) {
[379] Fix | Delete
$options['proxy'] = new Requests_Proxy_HTTP( $proxy->host() . ':' . $proxy->port() );
[380] Fix | Delete
[381] Fix | Delete
if ( $proxy->use_authentication() ) {
[382] Fix | Delete
$options['proxy']->use_authentication = true;
[383] Fix | Delete
$options['proxy']->user = $proxy->username();
[384] Fix | Delete
$options['proxy']->pass = $proxy->password();
[385] Fix | Delete
}
[386] Fix | Delete
}
[387] Fix | Delete
[388] Fix | Delete
// Avoid issues where mbstring.func_overload is enabled.
[389] Fix | Delete
mbstring_binary_safe_encoding();
[390] Fix | Delete
[391] Fix | Delete
try {
[392] Fix | Delete
$requests_response = Requests::request( $url, $headers, $data, $type, $options );
[393] Fix | Delete
[394] Fix | Delete
// Convert the response into an array.
[395] Fix | Delete
$http_response = new WP_HTTP_Requests_Response( $requests_response, $parsed_args['filename'] );
[396] Fix | Delete
$response = $http_response->to_array();
[397] Fix | Delete
[398] Fix | Delete
// Add the original object to the array.
[399] Fix | Delete
$response['http_response'] = $http_response;
[400] Fix | Delete
} catch ( Requests_Exception $e ) {
[401] Fix | Delete
$response = new WP_Error( 'http_request_failed', $e->getMessage() );
[402] Fix | Delete
}
[403] Fix | Delete
[404] Fix | Delete
reset_mbstring_encoding();
[405] Fix | Delete
[406] Fix | Delete
/**
[407] Fix | Delete
* Fires after an HTTP API response is received and before the response is returned.
[408] Fix | Delete
*
[409] Fix | Delete
* @since 2.8.0
[410] Fix | Delete
*
[411] Fix | Delete
* @param array|WP_Error $response HTTP response or WP_Error object.
[412] Fix | Delete
* @param string $context Context under which the hook is fired.
[413] Fix | Delete
* @param string $class HTTP transport used.
[414] Fix | Delete
* @param array $parsed_args HTTP request arguments.
[415] Fix | Delete
* @param string $url The request URL.
[416] Fix | Delete
*/
[417] Fix | Delete
do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
[418] Fix | Delete
if ( is_wp_error( $response ) ) {
[419] Fix | Delete
return $response;
[420] Fix | Delete
}
[421] Fix | Delete
[422] Fix | Delete
if ( ! $parsed_args['blocking'] ) {
[423] Fix | Delete
return array(
[424] Fix | Delete
'headers' => array(),
[425] Fix | Delete
'body' => '',
[426] Fix | Delete
'response' => array(
[427] Fix | Delete
'code' => false,
[428] Fix | Delete
'message' => false,
[429] Fix | Delete
),
[430] Fix | Delete
'cookies' => array(),
[431] Fix | Delete
'http_response' => null,
[432] Fix | Delete
);
[433] Fix | Delete
}
[434] Fix | Delete
[435] Fix | Delete
/**
[436] Fix | Delete
* Filters the HTTP API response immediately before the response is returned.
[437] Fix | Delete
*
[438] Fix | Delete
* @since 2.9.0
[439] Fix | Delete
*
[440] Fix | Delete
* @param array $response HTTP response.
[441] Fix | Delete
* @param array $parsed_args HTTP request arguments.
[442] Fix | Delete
* @param string $url The request URL.
[443] Fix | Delete
*/
[444] Fix | Delete
return apply_filters( 'http_response', $response, $parsed_args, $url );
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
/**
[448] Fix | Delete
* Normalizes cookies for using in Requests.
[449] Fix | Delete
*
[450] Fix | Delete
* @since 4.6.0
[451] Fix | Delete
*
[452] Fix | Delete
* @param array $cookies Array of cookies to send with the request.
[453] Fix | Delete
* @return Requests_Cookie_Jar Cookie holder object.
[454] Fix | Delete
*/
[455] Fix | Delete
public static function normalize_cookies( $cookies ) {
[456] Fix | Delete
$cookie_jar = new Requests_Cookie_Jar();
[457] Fix | Delete
[458] Fix | Delete
foreach ( $cookies as $name => $value ) {
[459] Fix | Delete
if ( $value instanceof WP_Http_Cookie ) {
[460] Fix | Delete
$cookie_jar[ $value->name ] = new Requests_Cookie( $value->name, $value->value, $value->get_attributes(), array( 'host-only' => $value->host_only ) );
[461] Fix | Delete
} elseif ( is_scalar( $value ) ) {
[462] Fix | Delete
$cookie_jar[ $name ] = new Requests_Cookie( $name, $value );
[463] Fix | Delete
}
[464] Fix | Delete
}
[465] Fix | Delete
[466] Fix | Delete
return $cookie_jar;
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
/**
[470] Fix | Delete
* Match redirect behaviour to browser handling.
[471] Fix | Delete
*
[472] Fix | Delete
* Changes 302 redirects from POST to GET to match browser handling. Per
[473] Fix | Delete
* RFC 7231, user agents can deviate from the strict reading of the
[474] Fix | Delete
* specification for compatibility purposes.
[475] Fix | Delete
*
[476] Fix | Delete
* @since 4.6.0
[477] Fix | Delete
*
[478] Fix | Delete
* @param string $location URL to redirect to.
[479] Fix | Delete
* @param array $headers Headers for the redirect.
[480] Fix | Delete
* @param string|array $data Body to send with the request.
[481] Fix | Delete
* @param array $options Redirect request options.
[482] Fix | Delete
* @param Requests_Response $original Response object.
[483] Fix | Delete
*/
[484] Fix | Delete
public static function browser_redirect_compatibility( $location, $headers, $data, &$options, $original ) {
[485] Fix | Delete
// Browser compatibility.
[486] Fix | Delete
if ( 302 === $original->status_code ) {
[487] Fix | Delete
$options['type'] = Requests::GET;
[488] Fix | Delete
}
[489] Fix | Delete
}
[490] Fix | Delete
[491] Fix | Delete
/**
[492] Fix | Delete
* Validate redirected URLs.
[493] Fix | Delete
*
[494] Fix | Delete
* @since 4.7.5
[495] Fix | Delete
*
[496] Fix | Delete
* @throws Requests_Exception On unsuccessful URL validation.
[497] Fix | Delete
* @param string $location URL to redirect to.
[498] Fix | Delete
*/
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function