wppaste
WordPress

WP_Http_Streams

Since
2.7.0, 3.7.0
Source
wp-includes/class-wp-http-streams.php:18
Core class used to integrate PHP Streams as an HTTP transport.

Hooks fired · 3

Every hook that fires from inside WP_Http_Streams, in the order it appears in the class, grouped by the method that fires it.

Methods · 3

  • request()Send a HTTP request to a URI using PHP Streams.
  • verify_ssl_certificate()Verifies the received SSL certificate against its Common Names and subjectAltName fields.
  • test()Determines whether this class can be used for retrieving a URL.

Source

#[AllowDynamicProperties]class WP_Http_Streams {	/**	 * Send a HTTP request to a URI using PHP Streams.	 *	 * @see WP_Http::request() For default options descriptions.	 *	 * @since 2.7.0	 * @since 3.7.0 Combined with the fsockopen transport and switched to stream_socket_client().	 *	 * @param string       $url  The request URL.	 * @param string|array $args Optional. Override the defaults.	 * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error	 */	public function request( $url, $args = array() ) {		$defaults = array(			'method'      => 'GET',			'timeout'     => 5,			'redirection' => 5,			'httpversion' => '1.0',			'blocking'    => true,			'headers'     => array(),			'body'        => null,			'cookies'     => array(),			'decompress'  => false,			'stream'      => false,			'filename'    => null,		); 		$parsed_args = wp_parse_args( $args, $defaults ); 		if ( isset( $parsed_args['headers']['User-Agent'] ) ) {			$parsed_args['user-agent'] = $parsed_args['headers']['User-Agent'];			unset( $parsed_args['headers']['User-Agent'] );		} elseif ( isset( $parsed_args['headers']['user-agent'] ) ) {			$parsed_args['user-agent'] = $parsed_args['headers']['user-agent'];			unset( $parsed_args['headers']['user-agent'] );		} 		// Construct Cookie: header if any cookies are set.		WP_Http::buildCookieHeader( $parsed_args ); 		$parsed_url = parse_url( $url ); 		$connect_host = $parsed_url['host']; 		$secure_transport = ( 'ssl' === $parsed_url['scheme'] || 'https' === $parsed_url['scheme'] );		if ( ! isset( $parsed_url['port'] ) ) {			if ( 'ssl' === $parsed_url['scheme'] || 'https' === $parsed_url['scheme'] ) {				$parsed_url['port'] = 443;				$secure_transport   = true;			} else {				$parsed_url['port'] = 80;			}		} 		// Always pass a path, defaulting to the root in cases such as http://example.com.		if ( ! isset( $parsed_url['path'] ) ) {			$parsed_url['path'] = '/';		} 		if ( isset( $parsed_args['headers']['Host'] ) || isset( $parsed_args['headers']['host'] ) ) {			if ( isset( $parsed_args['headers']['Host'] ) ) {				$parsed_url['host'] = $parsed_args['headers']['Host'];			} else {				$parsed_url['host'] = $parsed_args['headers']['host'];			}			unset( $parsed_args['headers']['Host'], $parsed_args['headers']['host'] );		} 		/*		 * Certain versions of PHP have issues with 'localhost' and IPv6, It attempts to connect		 * to ::1, which fails when the server is not set up for it. For compatibility, always		 * connect to the IPv4 address.		 */		if ( 'localhost' === strtolower( $connect_host ) ) {			$connect_host = '127.0.0.1';		} 		$connect_host = $secure_transport ? 'ssl://' . $connect_host : 'tcp://' . $connect_host;

History

Introduced in 2.7.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.4.0
Deprecated. Use WP_Httpfrom the docblock
3.7.0
Combined with the fsockopen transport and switched to stream_socket_client().from the docblock
2.7.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/class-wp-http-streams.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.