wp/wp-includes/class-wp-http-streams.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    10 /**
    10 /**
    11  * Core class used to integrate PHP Streams as an HTTP transport.
    11  * Core class used to integrate PHP Streams as an HTTP transport.
    12  *
    12  *
    13  * @since 2.7.0
    13  * @since 2.7.0
    14  * @since 3.7.0 Combined with the fsockopen transport and switched to `stream_socket_client()`.
    14  * @since 3.7.0 Combined with the fsockopen transport and switched to `stream_socket_client()`.
       
    15  * @deprecated 6.4.0 Use WP_Http
       
    16  * @see WP_Http
    15  */
    17  */
       
    18 #[AllowDynamicProperties]
    16 class WP_Http_Streams {
    19 class WP_Http_Streams {
    17 	/**
    20 	/**
    18 	 * Send a HTTP request to a URI using PHP Streams.
    21 	 * Send a HTTP request to a URI using PHP Streams.
    19 	 *
    22 	 *
    20 	 * @see WP_Http::request For default options descriptions.
    23 	 * @see WP_Http::request() For default options descriptions.
    21 	 *
    24 	 *
    22 	 * @since 2.7.0
    25 	 * @since 2.7.0
    23 	 * @since 3.7.0 Combined with the fsockopen transport and switched to stream_socket_client().
    26 	 * @since 3.7.0 Combined with the fsockopen transport and switched to stream_socket_client().
    24 	 *
    27 	 *
    25 	 * @param string       $url  The request URL.
    28 	 * @param string       $url  The request URL.
    34 			'httpversion' => '1.0',
    37 			'httpversion' => '1.0',
    35 			'blocking'    => true,
    38 			'blocking'    => true,
    36 			'headers'     => array(),
    39 			'headers'     => array(),
    37 			'body'        => null,
    40 			'body'        => null,
    38 			'cookies'     => array(),
    41 			'cookies'     => array(),
       
    42 			'decompress'  => false,
       
    43 			'stream'      => false,
       
    44 			'filename'    => null,
    39 		);
    45 		);
    40 
    46 
    41 		$parsed_args = wp_parse_args( $args, $defaults );
    47 		$parsed_args = wp_parse_args( $args, $defaults );
    42 
    48 
    43 		if ( isset( $parsed_args['headers']['User-Agent'] ) ) {
    49 		if ( isset( $parsed_args['headers']['User-Agent'] ) ) {
    98 			 * Filters whether SSL should be verified for local HTTP API requests.
   104 			 * Filters whether SSL should be verified for local HTTP API requests.
    99 			 *
   105 			 *
   100 			 * @since 2.8.0
   106 			 * @since 2.8.0
   101 			 * @since 5.1.0 The `$url` parameter was added.
   107 			 * @since 5.1.0 The `$url` parameter was added.
   102 			 *
   108 			 *
   103 			 * @param bool   $ssl_verify Whether to verify the SSL connection. Default true.
   109 			 * @param bool|string $ssl_verify Boolean to control whether to verify the SSL connection
   104 			 * @param string $url        The request URL.
   110 			 *                                or path to an SSL certificate.
       
   111 			 * @param string      $url        The request URL.
   105 			 */
   112 			 */
   106 			$ssl_verify = apply_filters( 'https_local_ssl_verify', $ssl_verify, $url );
   113 			$ssl_verify = apply_filters( 'https_local_ssl_verify', $ssl_verify, $url );
   107 		} elseif ( ! $is_local ) {
   114 		} elseif ( ! $is_local ) {
   108 			/** This filter is documented in wp-includes/class-wp-http.php */
   115 			/** This filter is documented in wp-includes/class-wp-http.php */
   109 			$ssl_verify = apply_filters( 'https_ssl_verify', $ssl_verify, $url );
   116 			$ssl_verify = apply_filters( 'https_ssl_verify', $ssl_verify, $url );
   122 					'allow_self_signed' => ! $ssl_verify,
   129 					'allow_self_signed' => ! $ssl_verify,
   123 				),
   130 				),
   124 			)
   131 			)
   125 		);
   132 		);
   126 
   133 
   127 		$timeout         = (int) floor( $parsed_args['timeout'] );
   134 		$timeout  = (int) floor( $parsed_args['timeout'] );
   128 		$utimeout        = $timeout == $parsed_args['timeout'] ? 0 : 1000000 * $parsed_args['timeout'] % 1000000;
   135 		$utimeout = 0;
       
   136 
       
   137 		if ( $timeout !== (int) $parsed_args['timeout'] ) {
       
   138 			$utimeout = 1000000 * $parsed_args['timeout'] % 1000000;
       
   139 		}
       
   140 
   129 		$connect_timeout = max( $timeout, 1 );
   141 		$connect_timeout = max( $timeout, 1 );
   130 
   142 
   131 		// Store error number.
   143 		// Store error number.
   132 		$connection_error = null;
   144 		$connection_error = null;
   133 
   145 
   213 
   225 
   214 		$headers = strtoupper( $parsed_args['method'] ) . ' ' . $request_path . ' HTTP/' . $parsed_args['httpversion'] . "\r\n";
   226 		$headers = strtoupper( $parsed_args['method'] ) . ' ' . $request_path . ' HTTP/' . $parsed_args['httpversion'] . "\r\n";
   215 
   227 
   216 		$include_port_in_host_header = (
   228 		$include_port_in_host_header = (
   217 			( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
   229 			( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
   218 			|| ( 'http' === $parsed_url['scheme'] && 80 != $parsed_url['port'] )
   230 			|| ( 'http' === $parsed_url['scheme'] && 80 !== $parsed_url['port'] )
   219 			|| ( 'https' === $parsed_url['scheme'] && 443 != $parsed_url['port'] )
   231 			|| ( 'https' === $parsed_url['scheme'] && 443 !== $parsed_url['port'] )
   220 		);
   232 		);
   221 
   233 
   222 		if ( $include_port_in_host_header ) {
   234 		if ( $include_port_in_host_header ) {
   223 			$headers .= 'Host: ' . $parsed_url['host'] . ':' . $parsed_url['port'] . "\r\n";
   235 			$headers .= 'Host: ' . $parsed_url['host'] . ':' . $parsed_url['port'] . "\r\n";
   224 		} else {
   236 		} else {
   316 					$block           = substr( $block, 0, $this_block_size );
   328 					$block           = substr( $block, 0, $this_block_size );
   317 				}
   329 				}
   318 
   330 
   319 				$bytes_written_to_file = fwrite( $stream_handle, $block );
   331 				$bytes_written_to_file = fwrite( $stream_handle, $block );
   320 
   332 
   321 				if ( $bytes_written_to_file != $this_block_size ) {
   333 				if ( $bytes_written_to_file !== $this_block_size ) {
   322 					fclose( $handle );
   334 					fclose( $handle );
   323 					fclose( $stream_handle );
   335 					fclose( $stream_handle );
   324 					return new WP_Error( 'http_request_failed', __( 'Failed to write request to temporary file.' ) );
   336 					return new WP_Error( 'http_request_failed', __( 'Failed to write request to temporary file.' ) );
   325 				}
   337 				}
   326 
   338