Ticket #4779: 4779.formatting2+non-blocking.diff
File 4779.formatting2+non-blocking.diff, 4.9 KB (added by , 13 years ago) |
---|
-
wp-includes/http.php
115 115 $defaults = array( 116 116 'method' => 'GET', 'timeout' => 3, 117 117 'redirection' => 5, 'redirected' => false, 118 'httpversion' => '1.0' 118 'httpversion' => '1.0', 'blocking' => true 119 119 ); 120 120 121 121 $r = wp_parse_args( $args, $defaults ); … … 261 261 $response = array('code' => 0, 'message' => ''); 262 262 263 263 $newheaders = array(); 264 foreach ($headers as $tempheader) {264 foreach ( $headers as $tempheader ) { 265 265 if ( empty($tempheader) ) 266 266 continue; 267 267 … … 306 306 function request($url, $args = array(), $headers = null, $body = null) { 307 307 $defaults = array( 308 308 'method' => 'GET', 'timeout' => 3, 309 'redirection' => 5, 'httpversion' => '1.0' 309 'redirection' => 5, 'httpversion' => '1.0', 310 'blocking' => true 310 311 ); 311 312 312 313 $r = wp_parse_args( $args, $defaults ); … … 323 324 $arrURL['host'] = 'ssl://' . $arrURL['host']; 324 325 $arrURL['port'] = apply_filters('http_request_default_port', 443); 325 326 $secure_transport = true; 327 } else { 328 $arrURL['port'] = apply_filters('http_request_default_port', 80); 326 329 } 327 else328 $arrURL['port'] = apply_filters('http_request_default_port', 80);330 } else { 331 $arrURL['port'] = apply_filters('http_request_port', $arrURL['port']); 329 332 } 330 else331 $arrURL['port'] = apply_filters('http_request_port', $arrURL['port']);332 333 333 334 if ( true === $secure_transport ) 334 335 $error_reporting = error_reporting(0); 335 336 336 337 $handle = fsockopen($arrURL['host'], $arrURL['port'], $iError, $strError, apply_filters('http_request_timeout', absint($r['timeout']) ) ); 337 338 338 if ( false === $handle ) {339 if ( false === $handle ) 339 340 return new WP_Error('http_request_failed', $iError . ': ' . $strError); 340 }341 341 342 342 $requestPath = $arrURL['path'] . ( isset($arrURL['query']) ? '?' . $arrURL['query'] : '' ); 343 $requestPath = (empty($requestPath)) ? '/' : $requestPath;343 $requestPath = empty($requestPath) ? '/' : $requestPath; 344 344 345 345 $strHeaders = ''; 346 346 $strHeaders .= strtoupper($r['method']) . ' ' . $requestPath . ' HTTP/' . $r['httpversion'] . "\r\n"; 347 347 $strHeaders .= 'Host: ' . $arrURL['host'] . "\r\n"; 348 348 349 349 if ( is_array($header) ) { 350 foreach ( (array) $this->getHeaders() as $header => $headerValue)350 foreach ( (array) $this->getHeaders() as $header => $headerValue ) 351 351 $strHeaders .= $header . ': ' . $headerValue . "\r\n"; 352 } else 352 } else { 353 353 $strHeaders .= $header; 354 } 354 355 355 356 $strHeaders .= "\r\n"; 356 357 … … 359 360 360 361 fwrite($handle, $strHeaders); 361 362 363 if ( ! $r['blocking']) ) 364 return array( 'headers' => array(), 'body' => '', 'response' => array() ); 365 362 366 $strResponse = ''; 363 367 while ( ! feof($handle) ) 364 368 $strResponse .= fread($handle, 4096); … … 430 434 431 435 $defaults = array( 432 436 'method' => 'GET', 'timeout' => 3, 433 'redirection' => 5, 'httpversion' => '1.0' 437 'redirection' => 5, 'httpversion' => '1.0', 438 'blocking' => true 434 439 ); 435 440 436 441 $r = wp_parse_args( $args, $defaults ); … … 448 453 if ( function_exists('stream_set_timeout') ) 449 454 stream_set_timeout($handle, apply_filters('http_request_timeout', $r['timeout']) ); 450 455 456 if ( ! $r['blocking']) ) 457 return array( 'headers' => array(), 'body' => '', 'response' => array() ); 458 451 459 $strResponse = ''; 452 460 while ( ! feof($handle) ) 453 461 $strResponse .= fread($handle, 4096); … … 507 515 function request($url, $args = array(), $headers = null, $body = null) { 508 516 $defaults = array( 509 517 'method' => 'GET', 'timeout' => 3, 510 'redirection' => 5, 'httpversion' => '1.0' 518 'redirection' => 5, 'httpversion' => '1.0', 519 'blocking' => true 511 520 ); 512 521 513 522 $r = wp_parse_args( $args, $defaults ); … … 536 545 537 546 stream_set_timeout($handle, apply_filters('http_request_stream_timeout', $this->timeout) ); 538 547 539 if ( ! $handle)548 if ( ! $handle) 540 549 return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url)); 541 550 551 if ( ! $r['blocking']) ) 552 return array( 'headers' => array(), 'body' => '', 'response' => array() ); 553 542 554 $strResponse = stream_get_contents($handle); 543 555 $meta = stream_get_meta_data($handle); 544 556 … … 574 586 * Requires the HTTP extension to be installed. 575 587 * 576 588 * Last ditch effort to retrieve the URL before complete failure. 589 * Does not support non-blocking requests. 577 590 * 578 591 * @package WordPress 579 592 * @subpackage HTTP … … 598 611 $defaults = array( 599 612 'method' => 'GET', 'timeout' => 3, 600 613 'redirection' => 5, 'httpversion' => '1.0', 601 ' user_agent' => apply_filters('http_headers_useragent', 'WordPress/' . $wp_version)614 'blocking' => true, 'user_agent' => apply_filters('http_headers_useragent', 'WordPress/' . $wp_version) 602 615 ); 603 616 604 617 $r = wp_parse_args( $args, $defaults ); … … 860 873 return $response['body']; 861 874 } 862 875 863 ?> 864 No newline at end of file 876 ?>