Changes from branches/3.0/wp-includes/class-http.php at r15283 to trunk/wp-includes/class-http.php at r17282
- File:
-
- 1 edited
-
trunk/wp-includes/class-http.php (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-http.php
r15283 r17282 239 239 return $pre; 240 240 241 $arrURL = parse_url( $url);241 $arrURL = parse_url( $url ); 242 242 243 243 if ( empty( $url ) || empty( $arrURL['scheme'] ) ) … … 245 245 246 246 if ( $this->block_request( $url ) ) 247 return new WP_Error( 'http_request_failed', __('User has blocked requests through HTTP.'));247 return new WP_Error( 'http_request_failed', __( 'User has blocked requests through HTTP.' ) ); 248 248 249 249 // Determine if this is a https call and pass that on to the transport functions … … 252 252 253 253 // Determine if this request is to OUR install of WordPress 254 $homeURL = parse_url( get_bloginfo( 'url') );254 $homeURL = parse_url( get_bloginfo( 'url' ) ); 255 255 $r['local'] = $homeURL['host'] == $arrURL['host'] || 'localhost' == $arrURL['host']; 256 unset( $homeURL);256 unset( $homeURL ); 257 257 258 258 if ( is_null( $r['headers'] ) ) 259 259 $r['headers'] = array(); 260 260 261 if ( ! is_array( $r['headers']) ) {262 $processedHeaders = WP_Http::processHeaders( $r['headers']);261 if ( ! is_array( $r['headers'] ) ) { 262 $processedHeaders = WP_Http::processHeaders( $r['headers'] ); 263 263 $r['headers'] = $processedHeaders['headers']; 264 264 } 265 265 266 if ( isset( $r['headers']['User-Agent']) ) {266 if ( isset( $r['headers']['User-Agent'] ) ) { 267 267 $r['user-agent'] = $r['headers']['User-Agent']; 268 unset( $r['headers']['User-Agent']);269 } 270 271 if ( isset( $r['headers']['user-agent']) ) {268 unset( $r['headers']['User-Agent'] ); 269 } 270 271 if ( isset( $r['headers']['user-agent'] ) ) { 272 272 $r['user-agent'] = $r['headers']['user-agent']; 273 unset( $r['headers']['user-agent']);273 unset( $r['headers']['user-agent'] ); 274 274 } 275 275 … … 281 281 282 282 if ( empty($r['body']) ) { 283 $r['body'] = null; 283 284 // Some servers fail when sending content without the content-length header being set. 284 285 // Also, to fix another bug, we only send when doing POST and PUT and the content-length 285 286 // header isn't already set. 286 if ( ($r['method'] == 'POST' || $r['method'] == 'PUT') && ! isset($r['headers']['Content-Length']) )287 if ( ($r['method'] == 'POST' || $r['method'] == 'PUT') && ! isset( $r['headers']['Content-Length'] ) ) 287 288 $r['headers']['Content-Length'] = 0; 288 289 … … 290 291 // this case is simply that we aren't sending any bodies and to get the transports that 291 292 // don't support sending bodies along with those which do. 292 $transports = WP_Http::_getTransport( $r);293 $transports = WP_Http::_getTransport( $r ); 293 294 } else { 294 295 if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) { 295 296 if ( ! version_compare(phpversion(), '5.1.2', '>=') ) 296 $r['body'] = _http_build_query( $r['body'], null, '&');297 $r['body'] = _http_build_query( $r['body'], null, '&' ); 297 298 else 298 $r['body'] = http_build_query( $r['body'], null, '&');299 $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset');300 $r['headers']['Content-Length'] = strlen( $r['body']);299 $r['body'] = http_build_query( $r['body'], null, '&' ); 300 $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ); 301 $r['headers']['Content-Length'] = strlen( $r['body'] ); 301 302 } 302 303 303 304 if ( ! isset( $r['headers']['Content-Length'] ) && ! isset( $r['headers']['content-length'] ) ) 304 $r['headers']['Content-Length'] = strlen( $r['body']);305 $r['headers']['Content-Length'] = strlen( $r['body'] ); 305 306 306 307 // The method is ambiguous, because we aren't talking about HTTP methods, the "post" in … … 308 309 // support sending the body. Not all do, depending on the limitations of the PHP core 309 310 // limitations. 310 $transports = WP_Http::_postTransport( $r);311 $transports = WP_Http::_postTransport( $r ); 311 312 } 312 313 … … 315 316 $response = array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() ); 316 317 foreach ( (array) $transports as $transport ) { 317 $response = $transport->request( $url, $r);318 319 do_action( 'http_api_debug', $response, 'response', get_class( $transport) );320 321 if ( ! is_wp_error( $response) )318 $response = $transport->request( $url, $r ); 319 320 do_action( 'http_api_debug', $response, 'response', get_class( $transport ) ); 321 322 if ( ! is_wp_error( $response ) ) 322 323 return apply_filters( 'http_response', $response, $r, $url ); 323 324 } … … 454 455 $newheaders[$key] = trim( $value ); 455 456 } 456 if ( 'set-cookie' == strtolower( $key ))457 if ( 'set-cookie' == $key ) 457 458 $cookies[] = new WP_Http_Cookie( $value ); 458 459 } … … 541 542 * file and this will only allow localhost and your blog to make requests. The constant 542 543 * WP_ACCESSIBLE_HOSTS will allow additional hosts to go through for requests. The format of the 543 * WP_ACCESSIBLE_HOSTS constant is a comma separated list of hostnames to allow. 544 * WP_ACCESSIBLE_HOSTS constant is a comma separated list of hostnames to allow, wildcard domains 545 * are supported, eg *.wordpress.org will allow for all subdomains of wordpress.org to be contacted. 544 546 * 545 547 * @since 2.8.0 546 548 * @link http://core.trac.wordpress.org/ticket/8927 Allow preventing external requests. 549 * @link http://core.trac.wordpress.org/ticket/14636 Allow wildcard domains in WP_ACCESSIBLE_HOSTS 547 550 * 548 551 * @param string $uri URI of url. … … 578 581 579 582 static $accessible_hosts; 580 if ( null == $accessible_hosts ) 583 static $wildcard_regex = false; 584 if ( null == $accessible_hosts ) { 581 585 $accessible_hosts = preg_split('|,\s*|', WP_ACCESSIBLE_HOSTS); 582 586 583 return !in_array( $check['host'], $accessible_hosts ); //Inverse logic, If its in the array, then we can't access it. 587 if ( false !== strpos(WP_ACCESSIBLE_HOSTS, '*') ) { 588 $wildcard_regex = array(); 589 foreach ( $accessible_hosts as $host ) 590 $wildcard_regex[] = str_replace('\*', '[\w.]+?', preg_quote($host, '/')); 591 $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i'; 592 } 593 } 594 595 if ( !empty($wildcard_regex) ) 596 return !preg_match($wildcard_regex, $check['host']); 597 else 598 return !in_array( $check['host'], $accessible_hosts ); //Inverse logic, If its in the array, then we can't access it. 599 600 601 584 602 } 585 603 } … … 622 640 $r['user-agent'] = $r['headers']['User-Agent']; 623 641 unset($r['headers']['User-Agent']); 624 } else if ( isset($r['headers']['user-agent']) ) {642 } else if ( isset($r['headers']['user-agent']) ) { 625 643 $r['user-agent'] = $r['headers']['user-agent']; 626 644 unset($r['headers']['user-agent']); … … 974 992 $r['user-agent'] = $r['headers']['User-Agent']; 975 993 unset($r['headers']['User-Agent']); 976 } else if ( isset($r['headers']['user-agent']) ) {994 } else if ( isset($r['headers']['user-agent']) ) { 977 995 $r['user-agent'] = $r['headers']['user-agent']; 978 996 unset($r['headers']['user-agent']); … … 1121 1139 * @since 2.7.0 1122 1140 */ 1123 class WP_Http_ExtH TTP{1141 class WP_Http_ExtHttp { 1124 1142 /** 1125 1143 * Send a HTTP request to a URI using HTTP extension. … … 1147 1165 $r['user-agent'] = $r['headers']['User-Agent']; 1148 1166 unset($r['headers']['User-Agent']); 1149 } else if ( isset($r['headers']['user-agent']) ) {1167 } else if ( isset($r['headers']['user-agent']) ) { 1150 1168 $r['user-agent'] = $r['headers']['user-agent']; 1151 1169 unset($r['headers']['user-agent']); … … 1297 1315 $r['user-agent'] = $r['headers']['User-Agent']; 1298 1316 unset($r['headers']['User-Agent']); 1299 } else if ( isset($r['headers']['user-agent']) ) {1317 } else if ( isset($r['headers']['user-agent']) ) { 1300 1318 $r['user-agent'] = $r['headers']['user-agent']; 1301 1319 unset($r['headers']['user-agent']); … … 1409 1427 else 1410 1428 $theBody = ''; 1411 if ( false !== str rpos($theHeaders, "\r\n\r\n") ) {1429 if ( false !== strpos($theHeaders, "\r\n\r\n") ) { 1412 1430 $headerParts = explode("\r\n\r\n", $theHeaders); 1413 1431 $theHeaders = $headerParts[ count($headerParts) -1 ]; … … 1479 1497 * <li>WP_PROXY_BYPASS_HOSTS - Will prevent the hosts in this list from going through the proxy. 1480 1498 * You do not need to have localhost and the blog host in this list, because they will not be passed 1481 * through the proxy. The list should be presented in a comma separated list </li>1499 * through the proxy. The list should be presented in a comma separated list, wildcards using * are supported, eg. *.wordpress.org</li> 1482 1500 * </ol> 1483 1501 * … … 1486 1504 * define('WP_PROXY_HOST', '192.168.84.101'); 1487 1505 * define('WP_PROXY_PORT', '8080'); 1488 * define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com ');1506 * define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com, *.wordpress.org'); 1489 1507 * </code> 1490 1508 * 1491 1509 * @link http://core.trac.wordpress.org/ticket/4011 Proxy support ticket in WordPress. 1510 * @link http://core.trac.wordpress.org/ticket/14636 Allow wildcard domains in WP_PROXY_BYPASS_HOSTS 1492 1511 * @since 2.8 1493 1512 */ … … 1606 1625 * 1607 1626 * @uses WP_PROXY_BYPASS_HOSTS 1608 * @since unknown1627 * @since 2.8.0 1609 1628 * 1610 1629 * @param string $uri URI to check. … … 1629 1648 1630 1649 static $bypass_hosts; 1631 if ( null == $bypass_hosts ) 1650 static $wildcard_regex = false; 1651 if ( null == $bypass_hosts ) { 1632 1652 $bypass_hosts = preg_split('|,\s*|', WP_PROXY_BYPASS_HOSTS); 1633 1653 1634 return !in_array( $check['host'], $bypass_hosts ); 1654 if ( false !== strpos(WP_PROXY_BYPASS_HOSTS, '*') ) { 1655 $wildcard_regex = array(); 1656 foreach ( $bypass_hosts as $host ) 1657 $wildcard_regex[] = str_replace('\*', '[\w.]+?', preg_quote($host, '/')); 1658 $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i'; 1659 } 1660 } 1661 1662 if ( !empty($wildcard_regex) ) 1663 return !preg_match($wildcard_regex, $check['host']); 1664 else 1665 return !in_array( $check['host'], $bypass_hosts ); 1635 1666 } 1636 1667 }
Note: See TracChangeset
for help on using the changeset viewer.