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