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