Ticket #26049: 26049.1.patch
File 26049.1.patch, 10.2 KB (added by , 11 years ago) |
---|
-
src/wp-includes/class-http.php
69 69 70 70 $defaults = array( 71 71 'method' => 'GET', 72 'timeout' => apply_filters( 'http_request_timeout', 5), 73 'redirection' => apply_filters( 'http_request_redirection_count', 5), 74 'httpversion' => apply_filters( 'http_request_version', '1.0'), 72 /** 73 * Filter the timeout value for an HTTP request. 74 * 75 * @since 2.7.0 76 * 77 * @param int $timeout_value Time in seconds until a request times out. 78 * Default 5. 79 */ 80 'timeout' => apply_filters( 'http_request_timeout', 5 ), 81 /** 82 * Filter the number of redirects allowed during an HTTP request. 83 * 84 * @since 2.7.0 85 * 86 * @param int $redirect_count Number of redirects allowed. Default 5. 87 */ 88 'redirection' => apply_filters( 'http_request_redirection_count', 5 ), 89 /** 90 * Filter the version of the HTTP protocol used in a request. 91 * 92 * @since 2.7.0 93 * 94 * @param string $version Version of HTTP used. Accepts '1.0' and '1.1'. 95 * Default '1.0'. 96 */ 97 'httpversion' => apply_filters( 'http_request_version', '1.0' ), 98 /** 99 * Filter the user agent value sent with an HTTP request. 100 * 101 * @since 2.7.0 102 * 103 * @param string $user_agent WordPress user agent string. 104 */ 75 105 'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ), 106 /** 107 * Filter whether to pass URLs through wp_http_validate_url() in an HTTP request. 108 * 109 * @since 3.6.0 110 * 111 * @param bool $pass_url Whether to pass URLs through wp_http_validate_url(). 112 * Default false. 113 */ 76 114 'reject_unsafe_urls' => apply_filters( 'http_request_reject_unsafe_urls', false ), 77 115 'blocking' => true, 78 116 'headers' => array(), … … 95 133 $defaults['redirection'] = 0; 96 134 97 135 $r = wp_parse_args( $args, $defaults ); 136 /** 137 * Filter the arguments used in an HTTP request. 138 * 139 * @since 2.7.0 140 * 141 * @param array $r An array of HTTP request arguments. 142 * @param string $url The request URI resource. 143 */ 98 144 $r = apply_filters( 'http_request_args', $r, $url ); 99 145 100 146 // The transports decrement this, store a copy of the original value for loop purposes. … … 101 147 if ( ! isset( $r['_redirection'] ) ) 102 148 $r['_redirection'] = $r['redirection']; 103 149 104 // Allow plugins to short-circuit the request 150 /** 151 * Filter whether to preempt an HTTP request return. 152 * 153 * Returning a truthy value to the filter will short-circuit 154 * the HTTP request and return early with that value. 155 * 156 * @since 2.9.0 157 * 158 * @param bool $preempt Whether to preempt an HTTP request return. Default false. 159 * @param array $r HTTP request arguments. 160 * @param string $url The request URI resource. 161 */ 105 162 $pre = apply_filters( 'pre_http_request', false, $r, $url ); 106 163 if ( false !== $pre ) 107 164 return $pre; … … 221 278 * @return string|bool Class name for the first transport that claims to support the request. False if no transport claims to support the request. 222 279 */ 223 280 public function _get_first_available_transport( $args, $url = null ) { 281 /** 282 * Filter which HTTP transports are available and in what order. 283 * 284 * @since 3.7.0 285 * 286 * @param array $value Array of HTTP transports to check. Default array contains 287 * 'curl', and 'streams', in that order. 288 * @param array $args HTTP request arguments. 289 * @param string $url The URL to request. 290 */ 224 291 $request_order = apply_filters( 'http_api_transports', array( 'curl', 'streams' ), $args, $url ); 225 292 226 293 // Loop over each transport on each HTTP request looking for one which will serve this request's needs … … 265 332 266 333 $response = $transports[$class]->request( $url, $args ); 267 334 335 /** 336 * Fires after an HTTP API response is received and before the response is returned. 337 * 338 * @since 2.8.0 339 * 340 * @param mixed $response HTTP Response or WP_Error object. 341 * @param string $context Context under which the hook is fired. 342 * @param string $class HTTP transport used. 343 * @param array $args HTTP request arguments. 344 * @param string $url The request URL. 345 */ 268 346 do_action( 'http_api_debug', $response, 'response', $class, $args, $url ); 269 347 270 348 if ( is_wp_error( $response ) ) 271 349 return $response; 272 350 351 /** 352 * Filter the HTTP API response immediately before the response is returned. 353 * 354 * @since 2.9.0 355 * 356 * @param array|obj $response HTTP Response. 357 * @param array $args HTTP request arguments. 358 * @param string $url The request URL. 359 */ 273 360 return apply_filters( 'http_response', $response, $args, $url ); 274 361 } 275 362 … … 516 603 $home = parse_url( get_option('siteurl') ); 517 604 518 605 // Don't block requests back to ourselves by default 519 if ( $check['host'] == 'localhost' || $check['host'] == $home['host'] ) 520 return apply_filters('block_local_requests', false); 606 if ( $check['host'] == 'localhost' || $check['host'] == $home['host'] ) { 607 /** 608 * Filter whether to block local requests through the proxy. 609 * 610 * @since 2.8.0 611 * 612 * @param bool $block Whether to block local requests through proxy. 613 * Default false. 614 */ 615 return apply_filters( 'block_local_requests', false ); 616 } 521 617 522 618 if ( !defined('WP_ACCESSIBLE_HOSTS') ) 523 619 return true; … … 742 838 743 839 $is_local = isset( $r['local'] ) && $r['local']; 744 840 $ssl_verify = isset( $r['sslverify'] ) && $r['sslverify']; 745 if ( $is_local ) 841 if ( $is_local ) { 842 /** 843 * Filter whether SSL should be verified for local requests. 844 * 845 * @since 2.8.0 846 * 847 * @param bool $ssl_verify Whether to verify the SSL connection. Default true. 848 */ 746 849 $ssl_verify = apply_filters( 'https_local_ssl_verify', $ssl_verify ); 747 elseif ( ! $is_local ) 850 } elseif ( ! $is_local ) { 851 /** 852 * Filter whether SSL should be verified for non-local requests. 853 * 854 * @since 2.8.0 855 * 856 * @param bool $ssl_verify Whether to verify the SSL connection. Default true. 857 */ 748 858 $ssl_verify = apply_filters( 'https_ssl_verify', $ssl_verify ); 859 } 749 860 750 861 $proxy = new WP_HTTP_Proxy(); 751 862 … … 1026 1137 return false; 1027 1138 } 1028 1139 1140 /** 1141 * Filter whether the WP_Http_Streams class can be used as a transport 1142 * for retrieving a URL. 1143 * 1144 * @since 2.7.0 1145 * 1146 * @param bool $use_class Whether the class can be used. Default true. 1147 * @param array $args Request arguments. 1148 */ 1029 1149 return apply_filters( 'use_streams_transport', true, $args ); 1030 1150 } 1031 1151 } … … 1145 1265 1146 1266 $is_local = isset($r['local']) && $r['local']; 1147 1267 $ssl_verify = isset($r['sslverify']) && $r['sslverify']; 1148 if ( $is_local ) 1149 $ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify); 1150 elseif ( ! $is_local ) 1151 $ssl_verify = apply_filters('https_ssl_verify', $ssl_verify); 1268 if ( $is_local ) { 1269 /** This filter is documented in wp-includes/class-http.php */ 1270 $ssl_verify = apply_filters( 'https_local_ssl_verify', $ssl_verify ); 1271 } elseif ( ! $is_local ) { 1272 /** This filter is documented in wp-includes/class-http.php */ 1273 $ssl_verify = apply_filters( 'https_ssl_verify', $ssl_verify ); 1274 } 1152 1275 1153 1276 // CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT expect integers. Have to use ceil since 1154 1277 // a value of 0 will allow an unlimited timeout. … … 1225 1348 else 1226 1349 curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 ); 1227 1350 1228 // Cookies are not handled by the HTTP API currently. Allow for plugin authors to handle it 1229 // themselves... Although, it is somewhat pointless without some reference. 1351 /** 1352 * Fires before the cURL process is executed. 1353 * 1354 * Cookies are not currently handled by the HTTP API. This action allows 1355 * plugins to handle cookies themselves. 1356 * 1357 * @since 2.8.0 1358 * 1359 * @param array $handle cURL options set using curl_setopt(). 1360 */ 1230 1361 do_action_ref_array( 'http_api_curl', array(&$handle) ); 1231 1362 1232 1363 // We don't need to return the body, so don't. Just execute request and return. … … 1361 1492 return false; 1362 1493 } 1363 1494 1495 /** 1496 * Filter whether the WP_Http_Curl class can be used as a transport 1497 * for retrieving a URL. 1498 * 1499 * @since 2.7.0 1500 * 1501 * @param bool $use_class Whether the class can be used. Default true. 1502 * @param array $args An array of request arguments. 1503 */ 1364 1504 return apply_filters( 'use_curl_transport', true, $args ); 1365 1505 } 1366 1506 } … … 1529 1669 1530 1670 $home = parse_url( get_option('siteurl') ); 1531 1671 1672 /** 1673 * Filter whether to preempt sending the request through the proxy server. 1674 * 1675 * Returning a false value will bypass the proxy; returning true will send 1676 * the request through the proxy. 1677 * 1678 * @since 3.5.0 1679 * 1680 * @param null $override Whether to override the request result. Default null. 1681 * @param string $uri URL to check. 1682 * @param array $check Associative array result of parsing the URI. 1683 * @param array $home Associative array result of parsing the site URL. 1684 */ 1532 1685 $result = apply_filters( 'pre_http_send_through_proxy', null, $uri, $check, $home ); 1533 1686 if ( ! is_null( $result ) ) 1534 1687 return $result; … … 1743 1896 if ( ! isset( $this->name ) || ! isset( $this->value ) ) 1744 1897 return ''; 1745 1898 1899 /** 1900 * Filter the header-encoded cookie value. 1901 * 1902 * @since 3.4.0 1903 * 1904 * @param string $value The cookie value. 1905 * @param string $name The cookie name. 1906 */ 1746 1907 return $this->name . '=' . apply_filters( 'wp_http_cookie_value', $this->value, $this->name ); 1747 1908 } 1748 1909 … … 1904 2065 $type[] = 'gzip;q=0.5'; 1905 2066 } 1906 2067 2068 /** 2069 * Filter the allowed encoding types. 2070 * 2071 * @since 3.6.0 2072 * 2073 * @param array $type Encoding types allowed. Accepts 'gzinflate', 2074 * 'gzuncompress', 'gzdecode'. 2075 * @param string $url URL of the HTTP request. 2076 * @param array $args HTTP request arguments. 2077 */ 1907 2078 $type = apply_filters( 'wp_http_accept_encoding', $type, $url, $args ); 1908 2079 1909 2080 return implode(', ', $type);