Changeset 10625
- Timestamp:
- 02/22/2009 09:58:47 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/http.php
r10565 r10625 229 229 230 230 if ( is_null($working_transport) ) { 231 if ( true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true)) {231 if ( true === WP_Http_ExtHttp::test() ) { 232 232 $working_transport['exthttp'] = new WP_Http_ExtHttp(); 233 233 $blocking_transport[] = &$working_transport['exthttp']; 234 } else if ( true === WP_Http_Curl::test() && apply_filters('use_curl_transport', true)) {234 } else if ( true === WP_Http_Curl::test() ) { 235 235 $working_transport['curl'] = new WP_Http_Curl(); 236 236 $blocking_transport[] = &$working_transport['curl']; 237 } else if ( true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true)) {237 } else if ( true === WP_Http_Streams::test() ) { 238 238 $working_transport['streams'] = new WP_Http_Streams(); 239 239 $blocking_transport[] = &$working_transport['streams']; 240 } else if ( true === WP_Http_Fopen::test() && apply_filters('use_fopen_transport', true) &&( isset($args['ssl']) && !$args['ssl'] ) ) {240 } else if ( true === WP_Http_Fopen::test() && ( isset($args['ssl']) && !$args['ssl'] ) ) { 241 241 $working_transport['fopen'] = new WP_Http_Fopen(); 242 242 $blocking_transport[] = &$working_transport['fopen']; 243 } else if ( true === WP_Http_Fsockopen::test() && apply_filters('use_fsockopen_transport', true) &&( isset($args['ssl']) && !$args['ssl'] ) ) {243 } else if ( true === WP_Http_Fsockopen::test() && ( isset($args['ssl']) && !$args['ssl'] ) ) { 244 244 $working_transport['fsockopen'] = new WP_Http_Fsockopen(); 245 245 $blocking_transport[] = &$working_transport['fsockopen']; … … 280 280 281 281 if ( is_null($working_transport) ) { 282 if ( true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true)) {282 if ( true === WP_Http_ExtHttp::test() ) { 283 283 $working_transport['exthttp'] = new WP_Http_ExtHttp(); 284 284 $blocking_transport[] = &$working_transport['exthttp']; 285 } else if ( true === WP_Http_Curl::test() && apply_filters('use_curl_transport', true)) {285 } else if ( true === WP_Http_Curl::test() ) { 286 286 $working_transport['curl'] = new WP_Http_Curl(); 287 287 $blocking_transport[] = &$working_transport['curl']; 288 } else if ( true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true)) {288 } else if ( true === WP_Http_Streams::test() ) { 289 289 $working_transport['streams'] = new WP_Http_Streams(); 290 290 $blocking_transport[] = &$working_transport['streams']; 291 } else if ( true === WP_Http_Fsockopen::test() && apply_filters('use_fsockopen_transport', true) &&( isset($args['ssl']) && !$args['ssl'] ) ) {291 } else if ( true === WP_Http_Fsockopen::test() && ( isset($args['ssl']) && !$args['ssl'] ) ) { 292 292 $working_transport['fsockopen'] = new WP_Http_Fsockopen(); 293 293 $blocking_transport[] = &$working_transport['fsockopen']; … … 377 377 $arrURL = parse_url($url); 378 378 379 if ( $this->block_request( $url ) ) 380 return new WP_Error('http_request_failed', 'User has blocked requests through HTTP.'); 381 379 382 // Determine if this is a https call and pass that on to the transport functions 380 383 // so that we can blacklist the transports that do not support ssl verification … … 401 404 unset($r['headers']['user-agent']); 402 405 } 403 406 404 407 // Construct Cookie: header if any cookies are set 405 408 WP_Http::buildCookieHeader( $r ); … … 515 518 * Transform header string into an array. 516 519 * 517 * If an array is given then it is assumed to be raw header data with 518 * numeric keys with the headers as the values. No headers must be passed 519 * that were already processed. 520 * If an array is given then it is assumed to be raw header data with numeric keys with the 521 * headers as the values. No headers must be passed that were already processed. 520 522 * 521 523 * @access public … … 565 567 /** 566 568 * Takes the arguments for a ::request() and checks for the cookie array. 567 * If it's found, then it's assumed to contain WP_Http_Cookie objects, which 568 * are each parsed into strings and added to the Cookie: header (within the 569 * arguments array). Edits the array by reference. 570 * 571 * @access public 569 * 570 * If it's found, then it's assumed to contain WP_Http_Cookie objects, which are each parsed 571 * into strings and added to the Cookie: header (within the arguments array). Edits the array by 572 * reference. 573 * 574 * @access public 575 * @version 2.8.0 572 576 * @static 573 577 * … … 584 588 } 585 589 } 586 590 587 591 /** 588 592 * Decodes chunk transfer-encoding, based off the HTTP 1.1 specification. … … 630 634 } 631 635 } 636 } 637 638 /** 639 * Block requests through the proxy. 640 * 641 * Those who are behind a proxy and want to prevent access to certain hosts may do so. This will 642 * prevent plugins from working and core functionality, if you don't include api.wordpress.org. 643 * 644 * You block external URL requests by defining WP_HTTP_BLOCK_EXTERNAL in your wp-config.php file 645 * and this will only allow localhost and your blog to make requests. The constant 646 * WP_ACCESSABLE_HOSTS will allow additional hosts to go through for requests. 647 * 648 * @since unknown 649 * @link http://core.trac.wordpress.org/ticket/8927 Allow preventing external requests. 650 * 651 * @param string $uri URI of url. 652 * @return bool True to block, false to allow. 653 */ 654 function block_request($uri) { 655 // We don't need to block requests, because nothing is blocked. 656 if ( ! defined('WP_HTTP_BLOCK_EXTERNAL') || ( defined('WP_HTTP_BLOCK_EXTERNAL') && WP_HTTP_BLOCK_EXTERNAL == false ) ) 657 return false; 658 659 // parse_url() only handles http, https type URLs, and will emit E_WARNING on failure. 660 // This will be displayed on blogs, which is not reasonable. 661 $check = @parse_url($uri); 662 663 /* Malformed URL, can not process, but this could mean ssl, so let through anyway. 664 * 665 * This isn't very security sound. There are instances where a hacker might attempt 666 * to bypass the proxy and this check. However, the reason for this behavior is that 667 * WordPress does not do any checking currently for non-proxy requests, so it is keeps with 668 * the default unsecure nature of the HTTP request. 669 */ 670 if ( $check === false ) 671 return false; 672 673 $home = parse_url( get_bloginfo('site_url') ); 674 675 // Don't block requests back to ourselves by default 676 if ( $uri == 'localhost' || $uri == $home['host'] ) 677 return apply_filters('block_local_requests', false); 678 679 if ( defined('WP_ACCESSABLE_HOSTS') && is_array( WP_ACCESSABLE_HOSTS ) && in_array( $check['host'], WP_ACCESSABLE_HOSTS ) ) { 680 return false; 681 } 682 683 return true; 632 684 } 633 685 } … … 800 852 801 853 if ( function_exists( 'fsockopen' ) ) 802 return true;854 return apply_filters('use_fsockopen_transport', true); 803 855 804 856 return false; … … 912 964 return false; 913 965 914 return true;966 return apply_filters('use_fopen_transport', true); 915 967 } 916 968 } … … 956 1008 unset($r['headers']['user-agent']); 957 1009 } 958 1010 959 1011 // Construct Cookie: header if any cookies are set 960 1012 WP_Http::buildCookieHeader( $r ); … … 985 1037 'timeout' => $r['timeout'], 986 1038 'ssl' => array( 987 988 989 1039 'verify_peer' => apply_filters('https_ssl_verify', $r['sslverify']), 1040 'verify_host' => apply_filters('https_ssl_verify', $r['sslverify']) 1041 ) 990 1042 ) 991 1043 ); … … 1050 1102 return false; 1051 1103 1052 return true;1104 return apply_filters('use_streams_transport', true); 1053 1105 } 1054 1106 } … … 1134 1186 $strResponse = http_request($r['method'], $url, $r['body'], $options, $info); //Emits warning level notices for max redirects and timeouts 1135 1187 1136 if ( false === $strResponse || ! empty($info['error']) ) //Error may still be set, Response may return headers or partial document, and error contains a reason the request was aborted, eg, timeout expired or max-redirects reached 1188 // Error may still be set, Response may return headers or partial document, and error 1189 // contains a reason the request was aborted, eg, timeout expired or max-redirects reached. 1190 if ( false === $strResponse || ! empty($info['error']) ) 1137 1191 return new WP_Error('http_request_failed', $info['response_code'] . ': ' . $info['error']); 1138 1192 … … 1170 1224 function test() { 1171 1225 if ( function_exists('http_request') ) 1172 return true;1226 return apply_filters('use_http_extension_transport', true); 1173 1227 1174 1228 return false; … … 1186 1240 */ 1187 1241 class WP_Http_Curl { 1242 1188 1243 /** 1189 1244 * Send a HTTP request to a URI using cURL extension. … … 1213 1268 unset($r['headers']['user-agent']); 1214 1269 } 1215 1270 1216 1271 // Construct Cookie: header if any cookies are set 1217 1272 WP_Http::buildCookieHeader( $r ); … … 1322 1377 function test() { 1323 1378 if ( function_exists('curl_init') && function_exists('curl_exec') ) 1324 return true;1379 return apply_filters('use_curl_transport', true); 1325 1380 1326 1381 return false; … … 1330 1385 1331 1386 /** 1332 * Internal representation of a cookie.1387 * Internal representation of a single cookie. 1333 1388 * 1334 1389 * Returned cookies are represented using this class, and when cookies are … … 1336 1391 * into one. 1337 1392 * 1393 * @todo The WordPress convention is to use underscores instead of camelCase for function and method 1394 * names. Need to switch to use underscores instead for the methods. 1395 * 1338 1396 * @package WordPress 1339 1397 * @subpackage HTTP 1398 * @since 2.8.0 1399 * @author Beau Lebens 1340 1400 */ 1341 1401 class WP_Http_Cookie { 1342 var $name, 1343 $value, 1344 $expires, 1345 $path, 1346 $domain; 1347 1348 /** 1349 * PHP4 style Constructor - Calls PHP5 Style Constructor 1402 1403 /** 1404 * Cookie name. 1405 * 1406 * @since 2.8.0 1407 * @var string 1408 */ 1409 var $name; 1410 1411 /** 1412 * Cookie value. 1413 * 1414 * @since 2.8.0 1415 * @var string 1416 */ 1417 var $value; 1418 1419 /** 1420 * When the cookie expires. 1421 * 1422 * @since 2.8.0 1423 * @var string 1424 */ 1425 var $expires; 1426 1427 /** 1428 * Cookie URL path. 1429 * 1430 * @since 2.8.0 1431 * @var string 1432 */ 1433 var $path; 1434 1435 /** 1436 * Cookie Domain. 1437 * 1438 * @since 2.8.0 1439 * @var string 1440 */ 1441 var $domain; 1442 1443 /** 1444 * PHP4 style Constructor - Calls PHP5 Style Constructor. 1445 * 1446 * @access public 1447 * @since 2.8.0 1448 * @param string|array $data Raw cookie data. 1350 1449 */ 1351 1450 function WP_Http_Cookie( $data ) { 1352 return$this->__construct( $data );1353 } 1354 1451 $this->__construct( $data ); 1452 } 1453 1355 1454 /** 1356 1455 * Sets up this cookie object. 1357 1456 * 1358 * @access public 1359 * 1360 * @param mixed $data Either an associative array describing the cookie, or a header-string detailing it. 1361 * If it's an array, it should include the following elements: 1362 * - name 1363 * - value [should NOT be urlencoded already] 1364 * - expires (optional) String or int (UNIX timestamp) 1365 * - path (optional) 1366 * - domain (optional) 1457 * The parameter $data should be either an associative array containing the indices names below 1458 * or a header string detailing it. 1459 * 1460 * If it's an array, it should include the following elements: 1461 * <ol> 1462 * <li>Name</li> 1463 * <li>Value - should NOT be urlencoded already.</li> 1464 * <li>Expires - (optional) String or int (UNIX timestamp).</li> 1465 * <li>Path (optional)</li> 1466 * <li>Domain (optional)</li> 1467 * </ol> 1468 * 1469 * @access public 1470 * @since 2.8.0 1471 * 1472 * @param string|array $data Raw cookie data. 1367 1473 */ 1368 1474 function __construct( $data ) { … … 1370 1476 // Assume it's a header string direct from a previous request 1371 1477 $pairs = explode( ';', $data ); 1372 1478 1373 1479 // Special handling for first pair; name=value. Also be careful of "=" in value 1374 1480 $name = trim( substr( $pairs[0], 0, strpos( $pairs[0], '=' ) ) ); … … 1377 1483 $this->value = urldecode( $value ); 1378 1484 array_shift( $pairs ); //Removes name=value from items. 1379 1485 1380 1486 // Set everything else as a property 1381 1487 foreach ( $pairs as $pair ) { 1382 1488 if ( empty($pair) ) //Handles the cookie ending in ; which results in a empty final pair 1383 1489 continue; 1490 1384 1491 list( $key, $val ) = explode( '=', $pair ); 1385 1492 $key = strtolower( trim( $key ) ); … … 1391 1498 if ( !isset( $data['name'] ) ) 1392 1499 return false; 1393 1500 1394 1501 // Set properties based directly on parameters 1395 1502 $this->name = $data['name']; … … 1397 1504 $this->path = isset( $data['path'] ) ? $data['path'] : ''; 1398 1505 $this->domain = isset( $data['domain'] ) ? $data['domain'] : ''; 1506 1399 1507 if ( isset( $data['expires'] ) ) 1400 1508 $this->expires = is_int( $data['expires'] ) ? $data['expires'] : strtotime( $data['expires'] ); … … 1403 1511 } 1404 1512 } 1405 1513 1406 1514 /** 1407 1515 * Confirms that it's OK to send this cookie to the URL checked against. … … 1410 1518 * 1411 1519 * @access public 1520 * @since 2.8.0 1412 1521 * 1413 1522 * @param string $url URL you intend to send this cookie to … … 1418 1527 if ( time() > $this->expires ) 1419 1528 return false; 1420 1529 1421 1530 // Get details on the URL we're thinking about sending to 1422 1531 $url = parse_url( $url ); 1423 1532 $url['port'] = isset( $url['port'] ) ? $url['port'] : 80; 1424 1533 $url['path'] = isset( $url['path'] ) ? $url['path'] : '/'; 1425 1426 1534 1535 // Values to use for comparison against the URL 1427 1536 $path = isset( $this->path ) ? $this->path : '/'; 1428 1537 $port = isset( $this->port ) ? $this->port : 80; … … 1430 1539 if ( false === stripos( $domain, '.' ) ) 1431 1540 $domain .= '.local'; 1432 1541 1433 1542 // Host - very basic check that the request URL ends with the domain restriction (minus leading dot) 1434 1543 $domain = substr( $domain, 0, 1 ) == '.' ? substr( $domain, 1 ) : $domain; 1435 1544 if ( substr( $url['host'], -strlen( $domain ) ) != $domain ) 1436 1545 return false; 1437 1546 1438 1547 // Port - supports "port-lists" in the format: "80,8000,8080" 1439 1548 if ( !in_array( $url['port'], explode( ',', $port) ) ) 1440 1549 return false; 1441 1550 1442 1551 // Path - request path must start with path restriction 1443 1552 if ( substr( $url['path'], 0, strlen( $path ) ) != $path ) 1444 1553 return false; 1445 1554 1446 1555 return true; 1447 1556 } 1448 1557 1558 /** 1559 * Convert cookie name and value back to header string. 1560 * 1561 * @access public 1562 * @since 2.8.0 1563 * 1564 * @return string Header encoded cookie name and value. 1565 */ 1449 1566 function getHeaderValue() { 1450 1567 if ( empty( $this->name ) || empty( $this->value ) ) … … 1453 1570 return $this->name . '=' . urlencode( $this->value ); 1454 1571 } 1455 1572 1573 /** 1574 * Retrieve cookie header for usage in the rest of the WordPress HTTP API. 1575 * 1576 * @access public 1577 * @since 2.8.0 1578 * 1579 * @return string 1580 */ 1456 1581 function getFullHeader() { 1457 1582 return 'Cookie: ' . $this->getHeaderValue();
Note: See TracChangeset
for help on using the changeset viewer.