Changeset 42343 for trunk/src/wp-includes/class-wp-http-curl.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/class-wp-http-curl.php (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-http-curl.php
r41901 r42343 68 68 * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error 69 69 */ 70 public function request( $url, $args = array()) {70 public function request( $url, $args = array() ) { 71 71 $defaults = array( 72 'method' => 'GET', 'timeout' => 5, 73 'redirection' => 5, 'httpversion' => '1.0', 74 'blocking' => true, 75 'headers' => array(), 'body' => null, 'cookies' => array() 72 'method' => 'GET', 73 'timeout' => 5, 74 'redirection' => 5, 75 'httpversion' => '1.0', 76 'blocking' => true, 77 'headers' => array(), 78 'body' => null, 79 'cookies' => array(), 76 80 ); 77 81 … … 106 110 } 107 111 108 $is_local = isset($r['local']) && $r['local'];109 $ssl_verify = isset( $r['sslverify']) && $r['sslverify'];112 $is_local = isset( $r['local'] ) && $r['local']; 113 $ssl_verify = isset( $r['sslverify'] ) && $r['sslverify']; 110 114 if ( $is_local ) { 111 115 /** This filter is documented in wp-includes/class-wp-http-streams.php */ … … 124 128 curl_setopt( $handle, CURLOPT_TIMEOUT, $timeout ); 125 129 126 curl_setopt( $handle, CURLOPT_URL, $url );130 curl_setopt( $handle, CURLOPT_URL, $url ); 127 131 curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true ); 128 132 curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, ( $ssl_verify === true ) ? 2 : false ); … … 140 144 */ 141 145 curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, false ); 142 if ( defined( 'CURLOPT_PROTOCOLS' ) ) // PHP 5.2.10 / cURL 7.19.4146 if ( defined( 'CURLOPT_PROTOCOLS' ) ) { // PHP 5.2.10 / cURL 7.19.4 143 147 curl_setopt( $handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS ); 148 } 144 149 145 150 switch ( $r['method'] ) { … … 157 162 default: 158 163 curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, $r['method'] ); 159 if ( ! is_null( $r['body'] ) ) 164 if ( ! is_null( $r['body'] ) ) { 160 165 curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] ); 166 } 161 167 break; 162 168 } … … 169 175 curl_setopt( $handle, CURLOPT_HEADER, false ); 170 176 171 if ( isset( $r['limit_response_size'] ) ) 177 if ( isset( $r['limit_response_size'] ) ) { 172 178 $this->max_body_length = intval( $r['limit_response_size'] ); 173 else179 } else { 174 180 $this->max_body_length = false; 181 } 175 182 176 183 // If streaming to a file open a file handle, and setup our curl streaming handler. 177 184 if ( $r['stream'] ) { 178 if ( ! WP_DEBUG ) 185 if ( ! WP_DEBUG ) { 179 186 $this->stream_handle = @fopen( $r['filename'], 'w+' ); 180 else187 } else { 181 188 $this->stream_handle = fopen( $r['filename'], 'w+' ); 189 } 182 190 if ( ! $this->stream_handle ) { 183 return new WP_Error( 'http_request_failed', sprintf( 184 /* translators: 1: fopen() 2: file name */ 185 __( 'Could not open handle for %1$s to %2$s.' ), 186 'fopen()', 187 $r['filename'] 188 ) ); 191 return new WP_Error( 192 'http_request_failed', sprintf( 193 /* translators: 1: fopen() 2: file name */ 194 __( 'Could not open handle for %1$s to %2$s.' ), 195 'fopen()', 196 $r['filename'] 197 ) 198 ); 189 199 } 190 200 } else { … … 192 202 } 193 203 194 if ( ! empty( $r['headers'] ) ) {204 if ( ! empty( $r['headers'] ) ) { 195 205 // cURL expects full header strings in each element. 196 206 $headers = array(); … … 201 211 } 202 212 203 if ( $r['httpversion'] == '1.0' ) 213 if ( $r['httpversion'] == '1.0' ) { 204 214 curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 ); 205 else215 } else { 206 216 curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 ); 217 } 207 218 208 219 /** … … 234 245 235 246 curl_close( $handle ); 236 return array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() ); 247 return array( 248 'headers' => array(), 249 'body' => '', 250 'response' => array( 251 'code' => false, 252 'message' => false, 253 ), 254 'cookies' => array(), 255 ); 237 256 } 238 257 239 258 curl_exec( $handle ); 240 $theHeaders = WP_Http::processHeaders( $this->headers, $url );241 $theBody = $this->body;259 $theHeaders = WP_Http::processHeaders( $this->headers, $url ); 260 $theBody = $this->body; 242 261 $bytes_written_total = $this->bytes_written_total; 243 262 244 $this->headers = '';245 $this->body = '';263 $this->headers = ''; 264 $this->body = ''; 246 265 $this->bytes_written_total = 0; 247 266 … … 275 294 curl_close( $handle ); 276 295 277 if ( $r['stream'] ) 296 if ( $r['stream'] ) { 278 297 fclose( $this->stream_handle ); 298 } 279 299 280 300 $response = array( 281 'headers' => $theHeaders['headers'],282 'body' => null,301 'headers' => $theHeaders['headers'], 302 'body' => null, 283 303 'response' => $theHeaders['response'], 284 'cookies' => $theHeaders['cookies'],285 'filename' => $r['filename'] 304 'cookies' => $theHeaders['cookies'], 305 'filename' => $r['filename'], 286 306 ); 287 307 288 308 // Handle redirects. 289 if ( false !== ( $redirect_response = WP_HTTP::handle_redirects( $url, $r, $response ) ) ) 309 if ( false !== ( $redirect_response = WP_HTTP::handle_redirects( $url, $r, $response ) ) ) { 290 310 return $redirect_response; 291 292 if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($theHeaders['headers']) ) 311 } 312 313 if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode( $theHeaders['headers'] ) ) { 293 314 $theBody = WP_Http_Encoding::decompress( $theBody ); 315 } 294 316 295 317 $response['body'] = $theBody; … … 333 355 if ( $this->max_body_length && ( $this->bytes_written_total + $data_length ) > $this->max_body_length ) { 334 356 $data_length = ( $this->max_body_length - $this->bytes_written_total ); 335 $data = substr( $data, 0, $data_length );357 $data = substr( $data, 0, $data_length ); 336 358 } 337 359 … … 339 361 $bytes_written = fwrite( $this->stream_handle, $data ); 340 362 } else { 341 $this->body .= $data;363 $this->body .= $data; 342 364 $bytes_written = $data_length; 343 365 } … … 359 381 */ 360 382 public static function test( $args = array() ) { 361 if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) ) 383 if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) ) { 362 384 return false; 385 } 363 386 364 387 $is_ssl = isset( $args['ssl'] ) && $args['ssl']; … … 367 390 $curl_version = curl_version(); 368 391 // Check whether this cURL version support SSL requests. 369 if ( ! ( CURL_VERSION_SSL & $curl_version['features']) )392 if ( ! ( CURL_VERSION_SSL & $curl_version['features'] ) ) { 370 393 return false; 394 } 371 395 } 372 396
Note: See TracChangeset
for help on using the changeset viewer.