* @access public
* @since 2.7.0
*
+ * @global string $wp_version
+ *
* @param string $url The request URL.
* @param string|array $args {
* Optional. Array or string of HTTP request arguments.
if ( function_exists( 'wp_kses_bad_protocol' ) ) {
if ( $r['reject_unsafe_urls'] )
$url = wp_http_validate_url( $url );
- $url = wp_kses_bad_protocol( $url, array( 'http', 'https', 'ssl' ) );
+ if ( $url ) {
+ $url = wp_kses_bad_protocol( $url, array( 'http', 'https', 'ssl' ) );
+ }
}
$arrURL = @parse_url( $url );
* and pick its name using the basename of the $url.
*/
if ( $r['stream'] && empty( $r['filename'] ) ) {
- $r['filename'] = wp_unique_filename( get_temp_dir(), basename( $url ) );
+ $r['filename'] = get_temp_dir() . wp_unique_filename( get_temp_dir(), basename( $url ) );
}
/*
$r['headers'] = array();
if ( ! is_array( $r['headers'] ) ) {
- $processedHeaders = WP_Http::processHeaders( $r['headers'], $url );
+ $processedHeaders = self::processHeaders( $r['headers'], $url );
$r['headers'] = $processedHeaders['headers'];
}
}
// Construct Cookie: header if any cookies are set.
- WP_Http::buildCookieHeader( $r );
+ self::buildCookieHeader( $r );
// Avoid issues where mbstring.func_overload is enabled.
mbstring_binary_safe_encoding();
* The order for requests is cURL, and then PHP Streams.
*
* @since 3.2.0
+ *
+ * @static
* @access private
*
* @param string $url URL to Request
* @link https://core.trac.wordpress.org/ticket/8927 Allow preventing external requests.
* @link https://core.trac.wordpress.org/ticket/14636 Allow wildcard domains in WP_ACCESSIBLE_HOSTS
*
+ * @staticvar array|null $accessible_hosts
+ * @staticvar array $wildcard_regex
+ *
* @param string $uri URI of url.
* @return bool True to block, false to allow.
*/
if ( !defined('WP_ACCESSIBLE_HOSTS') )
return true;
- static $accessible_hosts;
- static $wildcard_regex = false;
- if ( null == $accessible_hosts ) {
+ static $accessible_hosts = null;
+ static $wildcard_regex = array();
+ if ( null === $accessible_hosts ) {
$accessible_hosts = preg_split('|,\s*|', WP_ACCESSIBLE_HOSTS);
if ( false !== strpos(WP_ACCESSIBLE_HOSTS, '*') ) {
* when URL parsing failed.
*
* @since 4.1.0
+ *
+ * @static
* @access protected
*
* @param string $url The URL to parse.
*
* @since 3.4.0
*
+ * @static
* @access public
+ *
* @param string $maybe_relative_path The URL which might be relative
* @param string $url The URL which $maybe_relative_path is relative to
* @return string An Absolute URL, in a failure condition where the URL cannot be parsed, the relative URL will be returned.
*
* @since 3.7.0
*
+ * @static
+ *
* @param string $url The URL which was requested.
* @param array $args The Arguments which were used to make the request.
* @param array $response The Response of the HTTP request.
$r = wp_parse_args( $args, $defaults );
- if ( isset($r['headers']['User-Agent']) ) {
+ if ( isset( $r['headers']['User-Agent'] ) ) {
$r['user-agent'] = $r['headers']['User-Agent'];
- unset($r['headers']['User-Agent']);
- } else if ( isset($r['headers']['user-agent']) ) {
+ unset( $r['headers']['User-Agent'] );
+ } elseif ( isset( $r['headers']['user-agent'] ) ) {
$r['user-agent'] = $r['headers']['user-agent'];
- unset($r['headers']['user-agent']);
+ unset( $r['headers']['user-agent'] );
}
// Construct Cookie: header if any cookies are set.
* @since 2.7.0
* @since 3.7.0 Combined with the fsockopen transport and switched to stream_socket_client().
*
- * @return boolean False means this class can not be used, true means it can.
+ * @return bool False means this class can not be used, true means it can.
*/
public static function test( $args = array() ) {
if ( ! function_exists( 'stream_socket_client' ) )
$r = wp_parse_args( $args, $defaults );
- if ( isset($r['headers']['User-Agent']) ) {
+ if ( isset( $r['headers']['User-Agent'] ) ) {
$r['user-agent'] = $r['headers']['User-Agent'];
- unset($r['headers']['User-Agent']);
- } else if ( isset($r['headers']['user-agent']) ) {
+ unset( $r['headers']['User-Agent'] );
+ } elseif ( isset( $r['headers']['user-agent'] ) ) {
$r['user-agent'] = $r['headers']['user-agent'];
- unset($r['headers']['user-agent']);
+ unset( $r['headers']['user-agent'] );
}
// Construct Cookie: header if any cookies are set.
// If an error occurred, or, no response.
if ( $curl_error || ( 0 == strlen( $theBody ) && empty( $theHeaders['headers'] ) ) ) {
- if ( CURLE_WRITE_ERROR /* 23 */ == $curl_error && $r['stream'] ) {
+ if ( CURLE_WRITE_ERROR /* 23 */ == $curl_error ) {
if ( ! $this->max_body_length || $this->max_body_length != $bytes_written_total ) {
- fclose( $this->stream_handle );
- return new WP_Error( 'http_request_failed', __( 'Failed to write request to temporary file.' ) );
+ if ( $r['stream'] ) {
+ curl_close( $handle );
+ fclose( $this->stream_handle );
+ return new WP_Error( 'http_request_failed', __( 'Failed to write request to temporary file.' ) );
+ } else {
+ curl_close( $handle );
+ return new WP_Error( 'http_request_failed', curl_error( $handle ) );
+ }
}
} else {
if ( $curl_error = curl_error( $handle ) ) {
* @static
* @since 2.7.0
*
- * @return boolean False means this class can not be used, true means it can.
+ * @return bool False means this class can not be used, true means it can.
*/
public static function test( $args = array() ) {
if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) )
*
* @since 2.8.0
*
+ * @staticvar array|null $bypass_hosts
+ * @staticvar array $wildcard_regex
+ *
* @param string $uri URI to check.
* @return bool True, to send through the proxy and false if, the proxy should not be used.
*/
if ( !defined('WP_PROXY_BYPASS_HOSTS') )
return true;
- static $bypass_hosts;
- static $wildcard_regex = false;
- if ( null == $bypass_hosts ) {
+ static $bypass_hosts = null;
+ static $wildcard_regex = array();
+ if ( null === $bypass_hosts ) {
$bypass_hosts = preg_split('|,\s*|', WP_PROXY_BYPASS_HOSTS);
if ( false !== strpos(WP_PROXY_BYPASS_HOSTS, '*') ) {
}
} else {
if ( !isset( $data['name'] ) )
- return false;
+ return;
// Set properties based directly on parameters.
foreach ( array( 'name', 'value', 'path', 'domain', 'port' ) as $field ) {
* @since 2.8.0
*
* @param string $url URL you intend to send this cookie to
- * @return boolean true if allowed, false otherwise.
+ * @return bool true if allowed, false otherwise.
*/
public function test( $url ) {
if ( is_null( $this->name ) )
*
* @since 2.8.0
*
+ * @static
+ *
* @param string $raw String to compress.
* @param int $level Optional, default is 9. Compression level, 9 is highest.
* @param string $supports Optional, not used. When implemented it will choose the right compression based on what the server supports.
*
* @since 2.8.0
*
+ * @static
+ *
* @param string $compressed String to decompress.
* @param int $length The optional length of the compressed data.
* @return string|bool False on failure.
if ( false !== ( $decompressed = @gzinflate( $compressed ) ) )
return $decompressed;
- if ( false !== ( $decompressed = WP_Http_Encoding::compatible_gzinflate( $compressed ) ) )
+ if ( false !== ( $decompressed = self::compatible_gzinflate( $compressed ) ) )
return $decompressed;
if ( false !== ( $decompressed = @gzuncompress( $compressed ) ) )
* @link http://au2.php.net/manual/en/function.gzinflate.php#70875
* @link http://au2.php.net/manual/en/function.gzinflate.php#77336
*
+ * @static
+ *
* @param string $gzData String to decompress.
* @return string|bool False on failure.
*/
*
* @since 2.8.0
*
+ * @static
+ *
* @param string $url
* @param array $args
* @return string Types of encoding to accept.
*/
public static function accept_encoding( $url, $args ) {
$type = array();
- $compression_enabled = WP_Http_Encoding::is_available();
+ $compression_enabled = self::is_available();
if ( ! $args['decompress'] ) // Decompression specifically disabled.
$compression_enabled = false;
*
* @since 2.8.0
*
+ * @static
+ *
* @return string Content-Encoding string to send in the header.
*/
public static function content_encoding() {
*
* @since 2.8.0
*
+ * @static
+ *
* @param array|string $headers All of the available headers.
* @return bool
*/
if ( is_array( $headers ) ) {
if ( array_key_exists('content-encoding', $headers) && ! empty( $headers['content-encoding'] ) )
return true;
- } else if ( is_string( $headers ) ) {
+ } elseif ( is_string( $headers ) ) {
return ( stripos($headers, 'content-encoding:') !== false );
}
*
* @since 2.8.0
*
+ * @static
+ *
* @return bool
*/
public static function is_available() {