~ubuntu-branches/debian/jessie/wordpress/jessie

« back to all changes in this revision

Viewing changes to wp-includes/class-http.php

  • Committer: Package Import Robot
  • Author(s): Craig Small
  • Date: 2014-04-17 20:56:19 UTC
  • mfrom: (1.2.35)
  • Revision ID: package-import@ubuntu.com-20140417205619-nurbet6eho4yvwfv
Tags: 3.9+dfsg-1
* New upstream release
* 3.9 seems to handle different locations for plugins so the
  plugin directory handling patches have been cut back.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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's 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
 
281
368
         * @access public
282
369
         * @since 2.7.0
283
370
         *
284
 
         * @param string $url URI resource.
285
 
         * @param str|array $args Optional. Override the defaults.
 
371
         * @param string       $url  URI resource.
 
372
         * @param string|array $args Optional. Override the defaults.
286
373
         * @return array|object Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
287
374
         */
288
375
        function post($url, $args = array()) {
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;
670
766
/**
671
767
 * HTTP request method uses PHP Streams to retrieve the url.
672
768
 *
673
 
 * @package WordPress
674
 
 * @subpackage HTTP
675
 
 *
676
769
 * @since 2.7.0
677
770
 * @since 3.7.0 Combined with the fsockopen transport and switched to stream_socket_client().
678
771
 */
742
835
 
743
836
                $is_local = isset( $r['local'] ) && $r['local'];
744
837
                $ssl_verify = isset( $r['sslverify'] ) && $r['sslverify'];
745
 
                if ( $is_local )
 
838
                if ( $is_local ) {
 
839
                        /**
 
840
                         * Filter whether SSL should be verified for local requests.
 
841
                         *
 
842
                         * @since 2.8.0
 
843
                         *
 
844
                         * @param bool $ssl_verify Whether to verify the SSL connection. Default true.
 
845
                         */
746
846
                        $ssl_verify = apply_filters( 'https_local_ssl_verify', $ssl_verify );
747
 
                elseif ( ! $is_local )
 
847
                } elseif ( ! $is_local ) {
 
848
                        /**
 
849
                         * Filter whether SSL should be verified for non-local requests.
 
850
                         *
 
851
                         * @since 2.8.0
 
852
                         *
 
853
                         * @param bool $ssl_verify Whether to verify the SSL connection. Default true.
 
854
                         */
748
855
                        $ssl_verify = apply_filters( 'https_ssl_verify', $ssl_verify );
 
856
                }
749
857
 
750
858
                $proxy = new WP_HTTP_Proxy();
751
859
 
1004
1112
        }
1005
1113
 
1006
1114
        /**
1007
 
         * Whether this class can be used for retrieving an URL.
 
1115
         * Whether this class can be used for retrieving a URL.
1008
1116
         *
1009
1117
         * @static
1010
1118
         * @access public
1026
1134
                                return false;
1027
1135
                }
1028
1136
 
 
1137
                /**
 
1138
                 * Filter whether streams can be used as a transport for retrieving a URL.
 
1139
                 *
 
1140
                 * @since 2.7.0
 
1141
                 *
 
1142
                 * @param bool  $use_class Whether the class can be used. Default true.
 
1143
                 * @param array $args      Request arguments.
 
1144
                 */
1029
1145
                return apply_filters( 'use_streams_transport', true, $args );
1030
1146
        }
1031
1147
}
1038
1154
 *
1039
1155
 * @see WP_HTTP::request
1040
1156
 *
1041
 
 * @package WordPress
1042
 
 * @subpackage HTTP
1043
 
 *
1044
1157
 * @since 2.7.0
1045
1158
 * @deprecated 3.7.0 Please use WP_HTTP::request() directly
1046
1159
 */
1078
1191
        private $body = '';
1079
1192
 
1080
1193
        /**
1081
 
         * The maximum amount of data to recieve from the remote server
 
1194
         * The maximum amount of data to receive from the remote server.
1082
1195
         *
1083
1196
         * @since 3.6.0
1084
1197
         * @access private
1145
1258
 
1146
1259
                $is_local = isset($r['local']) && $r['local'];
1147
1260
                $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);
 
1261
                if ( $is_local ) {
 
1262
                        /** This filter is documented in wp-includes/class-http.php */
 
1263
                        $ssl_verify = apply_filters( 'https_local_ssl_verify', $ssl_verify );
 
1264
                } elseif ( ! $is_local ) {
 
1265
                        /** This filter is documented in wp-includes/class-http.php */
 
1266
                        $ssl_verify = apply_filters( 'https_ssl_verify', $ssl_verify );
 
1267
                }
1152
1268
 
1153
1269
                // CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT expect integers. Have to use ceil since
1154
1270
                // a value of 0 will allow an unlimited timeout.
1225
1341
                else
1226
1342
                        curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
1227
1343
 
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.
1230
 
                do_action_ref_array( 'http_api_curl', array(&$handle) );
 
1344
                /**
 
1345
                 * Fires before the cURL request is executed.
 
1346
                 *
 
1347
                 * Cookies are not currently handled by the HTTP API. This action allows
 
1348
                 * plugins to handle cookies themselves.
 
1349
                 *
 
1350
                 * @since 2.8.0
 
1351
                 *
 
1352
                 * @param resource &$handle The cURL handle returned by curl_init().
 
1353
                 * @param array    $r       The HTTP request arguments.
 
1354
                 * @param string   $url     The destination URL.
 
1355
                 */
 
1356
                do_action_ref_array( 'http_api_curl', array( &$handle, $r, $url ) );
1231
1357
 
1232
1358
                // We don't need to return the body, so don't. Just execute request and return.
1233
1359
                if ( ! $r['blocking'] ) {
1361
1487
                                return false;
1362
1488
                }
1363
1489
 
 
1490
                /**
 
1491
                 * Filter whether cURL can be used as a transport for retrieving a URL.
 
1492
                 *
 
1493
                 * @since 2.7.0
 
1494
                 *
 
1495
                 * @param bool  $use_class Whether the class can be used. Default true.
 
1496
                 * @param array $args      An array of request arguments.
 
1497
                 */
1364
1498
                return apply_filters( 'use_curl_transport', true, $args );
1365
1499
        }
1366
1500
}
1395
1529
 *
1396
1530
 * @link http://core.trac.wordpress.org/ticket/4011 Proxy support ticket in WordPress.
1397
1531
 * @link http://core.trac.wordpress.org/ticket/14636 Allow wildcard domains in WP_PROXY_BYPASS_HOSTS
1398
 
 * @since 2.8
 
1532
 * @since 2.8.0
1399
1533
 */
1400
1534
class WP_HTTP_Proxy {
1401
1535
 
1402
1536
        /**
1403
1537
         * Whether proxy connection should be used.
1404
1538
         *
1405
 
         * @since 2.8
 
1539
         * @since 2.8.0
 
1540
         *
1406
1541
         * @use WP_PROXY_HOST
1407
1542
         * @use WP_PROXY_PORT
1408
1543
         *
1415
1550
        /**
1416
1551
         * Whether authentication should be used.
1417
1552
         *
1418
 
         * @since 2.8
 
1553
         * @since 2.8.0
 
1554
         *
1419
1555
         * @use WP_PROXY_USERNAME
1420
1556
         * @use WP_PROXY_PASSWORD
1421
1557
         *
1428
1564
        /**
1429
1565
         * Retrieve the host for the proxy server.
1430
1566
         *
1431
 
         * @since 2.8
 
1567
         * @since 2.8.0
1432
1568
         *
1433
1569
         * @return string
1434
1570
         */
1442
1578
        /**
1443
1579
         * Retrieve the port for the proxy server.
1444
1580
         *
1445
 
         * @since 2.8
 
1581
         * @since 2.8.0
1446
1582
         *
1447
1583
         * @return string
1448
1584
         */
1456
1592
        /**
1457
1593
         * Retrieve the username for proxy authentication.
1458
1594
         *
1459
 
         * @since 2.8
 
1595
         * @since 2.8.0
1460
1596
         *
1461
1597
         * @return string
1462
1598
         */
1470
1606
        /**
1471
1607
         * Retrieve the password for proxy authentication.
1472
1608
         *
1473
 
         * @since 2.8
 
1609
         * @since 2.8.0
1474
1610
         *
1475
1611
         * @return string
1476
1612
         */
1484
1620
        /**
1485
1621
         * Retrieve authentication string for proxy authentication.
1486
1622
         *
1487
 
         * @since 2.8
 
1623
         * @since 2.8.0
1488
1624
         *
1489
1625
         * @return string
1490
1626
         */
1495
1631
        /**
1496
1632
         * Retrieve header string for proxy authentication.
1497
1633
         *
1498
 
         * @since 2.8
 
1634
         * @since 2.8.0
1499
1635
         *
1500
1636
         * @return string
1501
1637
         */
1527
1663
 
1528
1664
                $home = parse_url( get_option('siteurl') );
1529
1665
 
 
1666
                /**
 
1667
                 * Filter whether to preempt sending the request through the proxy server.
 
1668
                 *
 
1669
                 * Returning false will bypass the proxy; returning true will send
 
1670
                 * the request through the proxy. Returning null bypasses the filter.
 
1671
                 *
 
1672
                 * @since 3.5.0
 
1673
                 *
 
1674
                 * @param null   $override Whether to override the request result. Default null.
 
1675
                 * @param string $uri      URL to check.
 
1676
                 * @param array  $check    Associative array result of parsing the URI.
 
1677
                 * @param array  $home     Associative array result of parsing the site URL.
 
1678
                 */
1530
1679
                $result = apply_filters( 'pre_http_send_through_proxy', null, $uri, $check, $home );
1531
1680
                if ( ! is_null( $result ) )
1532
1681
                        return $result;
1741
1890
                if ( ! isset( $this->name ) || ! isset( $this->value ) )
1742
1891
                        return '';
1743
1892
 
 
1893
                /**
 
1894
                 * Filter the header-encoded cookie value.
 
1895
                 *
 
1896
                 * @since 3.4.0
 
1897
                 *
 
1898
                 * @param string $value The cookie value.
 
1899
                 * @param string $name  The cookie name.
 
1900
                 */
1744
1901
                return $this->name . '=' . apply_filters( 'wp_http_cookie_value', $this->value, $this->name );
1745
1902
        }
1746
1903
 
1762
1919
 *
1763
1920
 * Includes RFC 1950, RFC 1951, and RFC 1952.
1764
1921
 *
1765
 
 * @since 2.8
 
1922
 * @since 2.8.0
1766
1923
 * @package WordPress
1767
1924
 * @subpackage HTTP
1768
1925
 */
1773
1930
         *
1774
1931
         * Supports the RFC 1951 standard.
1775
1932
         *
1776
 
         * @since 2.8
 
1933
         * @since 2.8.0
1777
1934
         *
1778
1935
         * @param string $raw String to compress.
1779
1936
         * @param int $level Optional, default is 9. Compression level, 9 is highest.
1792
1949
         * 1952 standard gzip decode will be attempted. If all fail, then the
1793
1950
         * original compressed string will be returned.
1794
1951
         *
1795
 
         * @since 2.8
 
1952
         * @since 2.8.0
1796
1953
         *
1797
1954
         * @param string $compressed String to decompress.
1798
1955
         * @param int $length The optional length of the compressed data.
1876
2033
        /**
1877
2034
         * What encoding types to accept and their priority values.
1878
2035
         *
1879
 
         * @since 2.8
 
2036
         * @since 2.8.0
1880
2037
         *
1881
2038
         * @return string Types of encoding to accept.
1882
2039
         */
1902
2059
                                $type[] = 'gzip;q=0.5';
1903
2060
                }
1904
2061
 
 
2062
                /**
 
2063
                 * Filter the allowed encoding types.
 
2064
                 *
 
2065
                 * @since 3.6.0
 
2066
                 *
 
2067
                 * @param array  $type Encoding types allowed. Accepts 'gzinflate',
 
2068
                 *                     'gzuncompress', 'gzdecode'.
 
2069
                 * @param string $url  URL of the HTTP request.
 
2070
                 * @param array  $args HTTP request arguments.
 
2071
                 */
1905
2072
                $type = apply_filters( 'wp_http_accept_encoding', $type, $url, $args );
1906
2073
 
1907
2074
                return implode(', ', $type);
1910
2077
        /**
1911
2078
         * What encoding the content used when it was compressed to send in the headers.
1912
2079
         *
1913
 
         * @since 2.8
 
2080
         * @since 2.8.0
1914
2081
         *
1915
2082
         * @return string Content-Encoding string to send in the header.
1916
2083
         */
1921
2088
        /**
1922
2089
         * Whether the content be decoded based on the headers.
1923
2090
         *
1924
 
         * @since 2.8
 
2091
         * @since 2.8.0
1925
2092
         *
1926
2093
         * @param array|string $headers All of the available headers.
1927
2094
         * @return bool
1944
2111
         * ensure that the functions all exist in the PHP version and aren't
1945
2112
         * disabled.
1946
2113
         *
1947
 
         * @since 2.8
 
2114
         * @since 2.8.0
1948
2115
         *
1949
2116
         * @return bool
1950
2117
         */