/var/www/wordpress/wp-admin/includes/admin.php
/var/www/wordpress/wp-admin/includes/bookmark.php
/var/www/wordpress/wp-admin/includes/class-ftp-pure.php
/var/www/wordpress/wp-admin/includes/class-ftp-sockets.php
/var/www/wordpress/wp-admin/includes/class-ftp.php
/var/www/wordpress/wp-admin/includes/class-pclzip.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-base.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-direct.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ftpext.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ftpsockets.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ssh2.php
/var/www/wordpress/wp-admin/includes/class-wp-importer.php
/var/www/wordpress/wp-admin/includes/class-wp-upgrader.php
/var/www/wordpress/wp-admin/includes/comment.php
/var/www/wordpress/wp-admin/includes/continents-cities.php
/var/www/wordpress/wp-admin/includes/dashboard.php
/var/www/wordpress/wp-admin/includes/deprecated.php
/var/www/wordpress/wp-admin/includes/export.php
/var/www/wordpress/wp-admin/includes/file.php
/var/www/wordpress/wp-admin/includes/image-edit.php
/var/www/wordpress/wp-admin/includes/image.php
/var/www/wordpress/wp-admin/includes/import.php
/var/www/wordpress/wp-admin/includes/manifest.php
/var/www/wordpress/wp-admin/includes/media.php
/var/www/wordpress/wp-admin/includes/meta-boxes.php
/var/www/wordpress/wp-admin/includes/misc.php
/var/www/wordpress/wp-admin/includes/ms-deprecated.php
/var/www/wordpress/wp-admin/includes/ms.php
/var/www/wordpress/wp-admin/includes/nav-menu.php
/var/www/wordpress/wp-admin/includes/plugin-install.php
/var/www/wordpress/wp-admin/includes/plugin.php
/var/www/wordpress/wp-admin/includes/post.php
/var/www/wordpress/wp-admin/includes/schema.php
/var/www/wordpress/wp-admin/includes/taxonomy.php
/var/www/wordpress/wp-admin/includes/template.php
/var/www/wordpress/wp-admin/includes/theme-install.php
/var/www/wordpress/wp-admin/includes/theme.php
/var/www/wordpress/wp-admin/includes/update-core.php
/var/www/wordpress/wp-admin/includes/update.php
/var/www/wordpress/wp-admin/includes/upgrade.php
/var/www/wordpress/wp-admin/includes/user.php
/var/www/wordpress/wp-admin/includes/widgets.php
/var/www/wordpress/wp-admin/js/revisions-js.php
/var/www/wordpress/wp-admin/maint/repair.php
/var/www/wordpress/wp-admin/admin-ajax.php
/var/www/wordpress/wp-admin/admin-footer.php
/var/www/wordpress/wp-admin/admin-functions.php
/var/www/wordpress/wp-admin/admin-header.php
/var/www/wordpress/wp-admin/admin-post.php
/var/www/wordpress/wp-admin/admin.php
/var/www/wordpress/wp-admin/async-upload.php
/var/www/wordpress/wp-admin/comment.php
/var/www/wordpress/wp-admin/custom-background.php
/var/www/wordpress/wp-admin/custom-header.php
/var/www/wordpress/wp-admin/edit-attachment-rows.php
/var/www/wordpress/wp-admin/edit-comments.php
/var/www/wordpress/wp-admin/edit-form-advanced.php
/var/www/wordpress/wp-admin/edit-form-comment.php
/var/www/wordpress/wp-admin/edit-link-categories.php
/var/www/wordpress/wp-admin/edit-link-category-form.php
/var/www/wordpress/wp-admin/edit-link-form.php
/var/www/wordpress/wp-admin/edit-post-rows.php
/var/www/wordpress/wp-admin/edit-tag-form.php
/var/www/wordpress/wp-admin/edit-tags.php
/var/www/wordpress/wp-admin/edit.php
/var/www/wordpress/wp-admin/export.php
/var/www/wordpress/wp-admin/gears-manifest.php
/var/www/wordpress/wp-admin/import.php
/var/www/wordpress/wp-admin/index-extra.php
/var/www/wordpress/wp-admin/index.php
/var/www/wordpress/wp-admin/install-helper.php
/var/www/wordpress/wp-admin/install.php
/var/www/wordpress/wp-admin/link-add.php
/var/www/wordpress/wp-admin/link-category.php
/var/www/wordpress/wp-admin/link-manager.php
/var/www/wordpress/wp-admin/link-parse-opml.php
/var/www/wordpress/wp-admin/link.php
/var/www/wordpress/wp-admin/load-scripts.php
/var/www/wordpress/wp-admin/load-styles.php
/var/www/wordpress/wp-admin/media-new.php
/var/www/wordpress/wp-admin/media-upload.php
/var/www/wordpress/wp-admin/media.php
/var/www/wordpress/wp-admin/menu-header.php
/var/www/wordpress/wp-admin/menu.php
/var/www/wordpress/wp-admin/moderation.php
/var/www/wordpress/wp-admin/ms-admin.php
/var/www/wordpress/wp-admin/ms-delete-site.php
/var/www/wordpress/wp-admin/ms-edit.php
/var/www/wordpress/wp-admin/ms-options.php
/var/www/wordpress/wp-admin/ms-sites.php
/var/www/wordpress/wp-admin/ms-themes.php
/var/www/wordpress/wp-admin/ms-upgrade-network.php
/var/www/wordpress/wp-admin/ms-users.php
/var/www/wordpress/wp-admin/my-sites.php
/var/www/wordpress/wp-admin/nav-menus.php
/var/www/wordpress/wp-admin/network.php
/var/www/wordpress/wp-admin/options-discussion.php
/var/www/wordpress/wp-admin/options-general.php
/var/www/wordpress/wp-admin/options-head.php
/var/www/wordpress/wp-admin/options-media.php
/var/www/wordpress/wp-admin/options-permalink.php
/var/www/wordpress/wp-admin/options-privacy.php
/var/www/wordpress/wp-admin/options-reading.php
/var/www/wordpress/wp-admin/options-writing.php
/var/www/wordpress/wp-admin/options.php
/var/www/wordpress/wp-admin/plugin-editor.php
/var/www/wordpress/wp-admin/plugin-install.php
/var/www/wordpress/wp-admin/plugins.php
/var/www/wordpress/wp-admin/post-new.php
/var/www/wordpress/wp-admin/post.php
/var/www/wordpress/wp-admin/press-this.php
/var/www/wordpress/wp-admin/profile.php
/var/www/wordpress/wp-admin/revision.php
/var/www/wordpress/wp-admin/setup-config.php
/var/www/wordpress/wp-admin/sidebar.php
/var/www/wordpress/wp-admin/theme-editor.php
/var/www/wordpress/wp-admin/theme-install.php
/var/www/wordpress/wp-admin/themes.php
/var/www/wordpress/wp-admin/tools.php
/var/www/wordpress/wp-admin/update-core.php
/var/www/wordpress/wp-admin/update.php
/var/www/wordpress/wp-admin/upgrade-functions.php
/var/www/wordpress/wp-admin/upgrade.php
/var/www/wordpress/wp-admin/upload.php
/var/www/wordpress/wp-admin/user-edit.php
/var/www/wordpress/wp-admin/user-new.php
/var/www/wordpress/wp-admin/users.php
/var/www/wordpress/wp-admin/widgets.php
/var/www/wordpress/wp-content/languages/ru_RU.php
/var/www/wordpress/wp-content/plugins/akismet/akismet.php
/var/www/wordpress/wp-content/plugins/rh/rh.php
/var/www/wordpress/wp-content/plugins/hello.php
/var/www/wordpress/wp-content/plugins/index.php
/var/www/wordpress/wp-content/themes/twentyten/404.php
/var/www/wordpress/wp-content/themes/twentyten/archive.php
/var/www/wordpress/wp-content/themes/twentyten/attachment.php
/var/www/wordpress/wp-content/themes/twentyten/author.php
/var/www/wordpress/wp-content/themes/twentyten/category.php
/var/www/wordpress/wp-content/themes/twentyten/comments.php
/var/www/wordpress/wp-content/themes/twentyten/footer.php
/var/www/wordpress/wp-content/themes/twentyten/functions.php
/var/www/wordpress/wp-content/themes/twentyten/header.php
/var/www/wordpress/wp-content/themes/twentyten/index.php
/var/www/wordpress/wp-content/themes/twentyten/loop.php
/var/www/wordpress/wp-content/themes/twentyten/onecolumn-page.php
/var/www/wordpress/wp-content/themes/twentyten/page.php
/var/www/wordpress/wp-content/themes/twentyten/search.php
/var/www/wordpress/wp-content/themes/twentyten/sidebar-footer.php
/var/www/wordpress/wp-content/themes/twentyten/sidebar.php
/var/www/wordpress/wp-content/themes/twentyten/single.php
/var/www/wordpress/wp-content/themes/twentyten/tag.php
/var/www/wordpress/wp-content/themes/index.php
/var/www/wordpress/wp-content/index.php
/var/www/wordpress/wp-includes/js/tinymce/langs/wp-langs.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/Logger.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/EnchantSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/GoogleSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/PSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/PSpellShell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/SpellChecker.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/includes/general.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/config.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/rpc.php
/var/www/wordpress/wp-includes/js/tinymce/wp-mce-help.php
/var/www/wordpress/wp-includes/js/tinymce/wp-tinymce.php
/var/www/wordpress/wp-includes/pomo/entry.php
/var/www/wordpress/wp-includes/pomo/mo.php
/var/www/wordpress/wp-includes/pomo/po.php
/var/www/wordpress/wp-includes/pomo/streams.php
/var/www/wordpress/wp-includes/pomo/translations.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/native.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/shell.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/string.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/xdiff.php
/var/www/wordpress/wp-includes/Text/Diff/Renderer/inline.php
/var/www/wordpress/wp-includes/Text/Diff/Renderer.php
/var/www/wordpress/wp-includes/Text/Diff.php
/var/www/wordpress/wp-includes/theme-compat/comments-popup.php
/var/www/wordpress/wp-includes/theme-compat/comments.php
/var/www/wordpress/wp-includes/theme-compat/footer.php
/var/www/wordpress/wp-includes/theme-compat/header.php
/var/www/wordpress/wp-includes/theme-compat/sidebar.php
/var/www/wordpress/wp-includes/atomlib.php
/var/www/wordpress/wp-includes/author-template.php
/var/www/wordpress/wp-includes/bookmark-template.php
/var/www/wordpress/wp-includes/bookmark.php
/var/www/wordpress/wp-includes/cache.php
/var/www/wordpress/wp-includes/canonical.php
/var/www/wordpress/wp-includes/capabilities.php
/var/www/wordpress/wp-includes/category-template.php
/var/www/wordpress/wp-includes/category.php
/var/www/wordpress/wp-includes/class-feed.php
/var/www/wordpress/wp-includes/class-http.php
#CodeDescriptions
1<?php
2/**
3 * Simple and uniform HTTP request API.
4 *
5 * Standardizes the HTTP requests for WordPress. Handles cookies, gzip encoding and decoding, chunk
6 * decoding, if HTTP 1.1 and various other difficult HTTP protocol implementations.
7 *
8 * @link http://trac.wordpress.org/ticket/4779 HTTP API Proposal
9 *
10 * @package WordPress
11 * @subpackage HTTP
12 * @since 2.7.0
13 */
14
15/**
16 * WordPress HTTP Class for managing HTTP Transports and making HTTP requests.
17 *
18 * This class is called for the functionality of making HTTP requests and replaces Snoopy
19 * functionality. There is no available functionality to add HTTP transport implementations, since
20 * most of the HTTP transports are added and available for use.
21 *
22 * There are no properties, because none are needed and for performance reasons. Some of the
23 * functions are static and while they do have some overhead over functions in PHP4, the purpose is
24 * maintainability. When PHP5 is finally the requirement, it will be easy to add the static keyword
25 * to the code. It is not as easy to convert a function to a method after enough code uses the old
26 * way.
27 *
28 * Debugging includes several actions, which pass different variables for debugging the HTTP API.
29 *
30 * <strong>http_transport_get_debug</strong> - gives working, nonblocking, and blocking transports.
31 *
32 * <strong>http_transport_post_debug</strong> - gives working, nonblocking, and blocking transports.
33 *
34 * @package WordPress
35 * @subpackage HTTP
36 * @since 2.7.0
37 */
38class WP_Http {
39
40 /**
41 * PHP4 style Constructor - Calls PHP5 Style Constructor
42 *
43 * @since 2.7.0
44 * @return WP_Http
45 */
46 function WP_Http() {
47 $this->__construct();
48 }
49
50 /**
51 * PHP5 style Constructor - Set up available transport if not available.
52 *
53 * PHP4 does not have the 'self' keyword and since WordPress supports PHP4, the class needs to
54 * be used for the static call. The transport are set up to save time and will only be created
55 * once. This class can be created many times without having to go through the step of finding
56 * which transports are available.
57 *
58 * @since 2.7.0
59 * @return WP_Http
60 */
61 function __construct() {
62 WP_Http::_getTransport();
63 WP_Http::_postTransport();
64 }
65
66 /**
67 * Tests the WordPress HTTP objects for an object to use and returns it.
68 *
69 * Tests all of the objects and returns the object that passes. Also caches that object to be
70 * used later.
71 *
72 * The order for the GET/HEAD requests are HTTP Extension, cURL, Streams, Fopen, and finally
73 * Fsockopen. fsockopen() is used last, because it has the most overhead in its implementation.
74 * There isn't any real way around it, since redirects have to be supported, much the same way
75 * the other transports also handle redirects.
76 *
77 * There are currently issues with "localhost" not resolving correctly with DNS. This may cause
78 * an error "failed to open stream: A connection attempt failed because the connected party did
79 * not properly respond after a period of time, or established connection failed because [the]
80 * connected host has failed to respond."
81 *
82 * @since 2.7.0
83 * @access private
84 *
85 * @param array $args Request args, default us an empty array
86 * @return object|null Null if no transports are available, HTTP transport object.
87 */
88 function &_getTransport( $args = array() ) {
89 static $working_transport, $blocking_transport, $nonblocking_transport;
90
91 if ( is_null($working_transport) ) {
92 if ( true === WP_Http_ExtHttp::test($args) ) {
93 $working_transport['exthttp'] = new WP_Http_ExtHttp();
94 $blocking_transport[] = &$working_transport['exthttp'];
95 } else if ( true === WP_Http_Curl::test($args) ) {
96 $working_transport['curl'] = new WP_Http_Curl();
97 $blocking_transport[] = &$working_transport['curl'];
98 } else if ( true === WP_Http_Streams::test($args) ) {
99 $working_transport['streams'] = new WP_Http_Streams();
100 $blocking_transport[] = &$working_transport['streams'];
101 } else if ( true === WP_Http_Fopen::test($args) ) {
102 $working_transport['fopen'] = new WP_Http_Fopen();
103 $blocking_transport[] = &$working_transport['fopen'];
104 } else if ( true === WP_Http_Fsockopen::test($args) ) {
105 $working_transport['fsockopen'] = new WP_Http_Fsockopen();
106 $blocking_transport[] = &$working_transport['fsockopen'];
107 }
108
109 foreach ( array('curl', 'streams', 'fopen', 'fsockopen', 'exthttp') as $transport ) {
110 if ( isset($working_transport[$transport]) )
111 $nonblocking_transport[] = &$working_transport[$transport];
112 }
113 }
114
115 do_action( 'http_transport_get_debug', $working_transport, $blocking_transport, $nonblocking_transport );
116
117 if ( isset($args['blocking']) && !$args['blocking'] )
118 return $nonblocking_transport;
119 else
120 return $blocking_transport;
121 }
122
123 /**
124 * Tests the WordPress HTTP objects for an object to use and returns it.
125 *
126 * Tests all of the objects and returns the object that passes. Also caches
127 * that object to be used later. This is for posting content to a URL and
128 * is used when there is a body. The plain Fopen Transport can not be used
129 * to send content, but the streams transport can. This is a limitation that
130 * is addressed here, by just not including that transport.
131 *
132 * @since 2.7.0
133 * @access private
134 *
135 * @param array $args Request args, default us an empty array
136 * @return object|null Null if no transports are available, HTTP transport object.
137 */
138 function &_postTransport( $args = array() ) {
139 static $working_transport, $blocking_transport, $nonblocking_transport;
140
141 if ( is_null($working_transport) ) {
142 if ( true === WP_Http_ExtHttp::test($args) ) {
143 $working_transport['exthttp'] = new WP_Http_ExtHttp();
144 $blocking_transport[] = &$working_transport['exthttp'];
145 } else if ( true === WP_Http_Curl::test($args) ) {
146 $working_transport['curl'] = new WP_Http_Curl();
147 $blocking_transport[] = &$working_transport['curl'];
148 } else if ( true === WP_Http_Streams::test($args) ) {
149 $working_transport['streams'] = new WP_Http_Streams();
150 $blocking_transport[] = &$working_transport['streams'];
151 } else if ( true === WP_Http_Fsockopen::test($args) ) {
152 $working_transport['fsockopen'] = new WP_Http_Fsockopen();
153 $blocking_transport[] = &$working_transport['fsockopen'];
154 }
155
156 foreach ( array('curl', 'streams', 'fsockopen', 'exthttp') as $transport ) {
157 if ( isset($working_transport[$transport]) )
158 $nonblocking_transport[] = &$working_transport[$transport];
159 }
160 }
161
162 do_action( 'http_transport_post_debug', $working_transport, $blocking_transport, $nonblocking_transport );
163
164 if ( isset($args['blocking']) && !$args['blocking'] )
165 return $nonblocking_transport;
166 else
167 return $blocking_transport;
168 }
169
170 /**
171 * Send a HTTP request to a URI.
172 *
173 * The body and headers are part of the arguments. The 'body' argument is for the body and will
174 * accept either a string or an array. The 'headers' argument should be an array, but a string
175 * is acceptable. If the 'body' argument is an array, then it will automatically be escaped
176 * using http_build_query().
177 *
178 * The only URI that are supported in the HTTP Transport implementation are the HTTP and HTTPS
179 * protocols. HTTP and HTTPS are assumed so the server might not know how to handle the send
180 * headers. Other protocols are unsupported and most likely will fail.
181 *
182 * The defaults are 'method', 'timeout', 'redirection', 'httpversion', 'blocking' and
183 * 'user-agent'.
184 *
185 * Accepted 'method' values are 'GET', 'POST', and 'HEAD', some transports technically allow
186 * others, but should not be assumed. The 'timeout' is used to sent how long the connection
187 * should stay open before failing when no response. 'redirection' is used to track how many
188 * redirects were taken and used to sent the amount for other transports, but not all transports
189 * accept setting that value.
190 *
191 * The 'httpversion' option is used to sent the HTTP version and accepted values are '1.0', and
192 * '1.1' and should be a string. Version 1.1 is not supported, because of chunk response. The
193 * 'user-agent' option is the user-agent and is used to replace the default user-agent, which is
194 * 'WordPress/WP_Version', where WP_Version is the value from $wp_version.
195 *
196 * 'blocking' is the default, which is used to tell the transport, whether it should halt PHP
197 * while it performs the request or continue regardless. Actually, that isn't entirely correct.
198 * Blocking mode really just means whether the fread should just pull what it can whenever it
199 * gets bytes or if it should wait until it has enough in the buffer to read or finishes reading
200 * the entire content. It doesn't actually always mean that PHP will continue going after making
201 * the request.
202 *
203 * @access public
204 * @since 2.7.0
205 * @todo Refactor this code. The code in this method extends the scope of its original purpose
206 * and should be refactored to allow for cleaner abstraction and reduce duplication of the
207 * code. One suggestion is to create a class specifically for the arguments, however
208 * preliminary refactoring to this affect has affect more than just the scope of the
209 * arguments. Something to ponder at least.
210 *
211 * @param string $url URI resource.
212 * @param str|array $args Optional. Override the defaults.
213 * @return array containing 'headers', 'body', 'response', 'cookies'
214 */
215 function request( $url, $args = array() ) {
216 global $wp_version;
217
218 $defaults = array(
219 'method' => 'GET',
220 'timeout' => apply_filters( 'http_request_timeout', 5),
221 'redirection' => apply_filters( 'http_request_redirection_count', 5),
222 'httpversion' => apply_filters( 'http_request_version', '1.0'),
223 'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ),
224 'blocking' => true,
225 'headers' => array(),
226 'cookies' => array(),
227 'body' => null,
228 'compress' => false,
229 'decompress' => true,
230 'sslverify' => true
231 );
232
233 $r = wp_parse_args( $args, $defaults );
234 $r = apply_filters( 'http_request_args', $r, $url );
235
236 // Allow plugins to short-circuit the request
237 $pre = apply_filters( 'pre_http_request', false, $r, $url );
238 if ( false !== $pre )
239 return $pre;
240
241 $arrURL = parse_url($url);
242
243 if ( empty( $url ) || empty( $arrURL['scheme'] ) )
244 return new WP_Error('http_request_failed', __('A valid URL was not provided.'));
245
246 if ( $this->block_request( $url ) )
247 return new WP_Error('http_request_failed', __('User has blocked requests through HTTP.'));
248
249 // Determine if this is a https call and pass that on to the transport functions
250 // so that we can blacklist the transports that do not support ssl verification
251 $r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl';
252
253 // Determine if this request is to OUR install of WordPress
254 $homeURL = parse_url( get_bloginfo('url') );
255 $r['local'] = $homeURL['host'] == $arrURL['host'] || 'localhost' == $arrURL['host'];
256 unset($homeURL);
257
258 if ( is_null( $r['headers'] ) )
259 $r['headers'] = array();
260
261 if ( ! is_array($r['headers']) ) {
262 $processedHeaders = WP_Http::processHeaders($r['headers']);
263 $r['headers'] = $processedHeaders['headers'];
264 }
265
266 if ( isset($r['headers']['User-Agent']) ) {
267 $r['user-agent'] = $r['headers']['User-Agent'];
268 unset($r['headers']['User-Agent']);
269 }
270
271 if ( isset($r['headers']['user-agent']) ) {
272 $r['user-agent'] = $r['headers']['user-agent'];
273 unset($r['headers']['user-agent']);
274 }
275
276 // Construct Cookie: header if any cookies are set
277 WP_Http::buildCookieHeader( $r );
278
279 if ( WP_Http_Encoding::is_available() )
280 $r['headers']['Accept-Encoding'] = WP_Http_Encoding::accept_encoding();
281
282 if ( empty($r['body']) ) {
283 // Some servers fail when sending content without the content-length header being set.
284 // Also, to fix another bug, we only send when doing POST and PUT and the content-length
285 // header isn't already set.
286 if( ($r['method'] == 'POST' || $r['method'] == 'PUT') && ! isset($r['headers']['Content-Length']) )
287 $r['headers']['Content-Length'] = 0;
288
289 // The method is ambiguous, because we aren't talking about HTTP methods, the "get" in
290 // this case is simply that we aren't sending any bodies and to get the transports that
291 // don't support sending bodies along with those which do.
292 $transports = WP_Http::_getTransport($r);
293 } else {
294 if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) {
295 if ( ! version_compare(phpversion(), '5.1.2', '>=') )
296 $r['body'] = _http_build_query($r['body'], null, '&');
297 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']);
301 }
302
303 if ( ! isset( $r['headers']['Content-Length'] ) && ! isset( $r['headers']['content-length'] ) )
304 $r['headers']['Content-Length'] = strlen($r['body']);
305
306 // The method is ambiguous, because we aren't talking about HTTP methods, the "post" in
307 // this case is simply that we are sending HTTP body and to get the transports that do
308 // support sending the body. Not all do, depending on the limitations of the PHP core
309 // limitations.
310 $transports = WP_Http::_postTransport($r);
311 }
312
313 do_action( 'http_api_debug', $transports, 'transports_list' );
314
315 $response = array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() );
316 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) )
322 return apply_filters( 'http_response', $response, $r, $url );
323 }
324
325 return $response;
326 }
327
328 /**
329 * Uses the POST HTTP method.
330 *
331 * Used for sending data that is expected to be in the body.
332 *
333 * @access public
334 * @since 2.7.0
335 *
336 * @param string $url URI resource.
337 * @param str|array $args Optional. Override the defaults.
338 * @return boolean
339 */
340 function post($url, $args = array()) {
341 $defaults = array('method' => 'POST');
342 $r = wp_parse_args( $args, $defaults );
343 return $this->request($url, $r);
344 }
345
346 /**
347 * Uses the GET HTTP method.
348 *
349 * Used for sending data that is expected to be in the body.
350 *
351 * @access public
352 * @since 2.7.0
353 *
354 * @param string $url URI resource.
355 * @param str|array $args Optional. Override the defaults.
356 * @return boolean
357 */
358 function get($url, $args = array()) {
359 $defaults = array('method' => 'GET');
360 $r = wp_parse_args( $args, $defaults );
361 return $this->request($url, $r);
362 }
363
364 /**
365 * Uses the HEAD HTTP method.
366 *
367 * Used for sending data that is expected to be in the body.
368 *
369 * @access public
370 * @since 2.7.0
371 *
372 * @param string $url URI resource.
373 * @param str|array $args Optional. Override the defaults.
374 * @return boolean
375 */
376 function head($url, $args = array()) {
377 $defaults = array('method' => 'HEAD');
378 $r = wp_parse_args( $args, $defaults );
379 return $this->request($url, $r);
380 }
381
382 /**
383 * Parses the responses and splits the parts into headers and body.
384 *
385 * @access public
386 * @static
387 * @since 2.7.0
388 *
389 * @param string $strResponse The full response string
390 * @return array Array with 'headers' and 'body' keys.
391 */
392 function processResponse($strResponse) {
393 $res = explode("\r\n\r\n", $strResponse, 2);
394
395 return array('headers' => isset($res[0]) ? $res[0] : array(), 'body' => isset($res[1]) ? $res[1] : '');
396 }
397
398 /**
399 * Transform header string into an array.
400 *
401 * If an array is given then it is assumed to be raw header data with numeric keys with the
402 * headers as the values. No headers must be passed that were already processed.
403 *
404 * @access public
405 * @static
406 * @since 2.7.0
407 *
408 * @param string|array $headers
409 * @return array Processed string headers. If duplicate headers are encountered,
410 * Then a numbered array is returned as the value of that header-key.
411 */
412 function processHeaders($headers) {
413 // split headers, one per array element
414 if ( is_string($headers) ) {
415 // tolerate line terminator: CRLF = LF (RFC 2616 19.3)
416 $headers = str_replace("\r\n", "\n", $headers);
417 // unfold folded header fields. LWS = [CRLF] 1*( SP | HT ) <US-ASCII SP, space (32)>, <US-ASCII HT, horizontal-tab (9)> (RFC 2616 2.2)
418 $headers = preg_replace('/\n[ \t]/', ' ', $headers);
419 // create the headers array
420 $headers = explode("\n", $headers);
421 }
422
423 $response = array('code' => 0, 'message' => '');
424
425 // If a redirection has taken place, The headers for each page request may have been passed.
426 // In this case, determine the final HTTP header and parse from there.
427 for ( $i = count($headers)-1; $i >= 0; $i-- ) {
428 if ( !empty($headers[$i]) && false === strpos($headers[$i], ':') ) {
429 $headers = array_splice($headers, $i);
430 break;
431 }
432 }
433
434 $cookies = array();
435 $newheaders = array();
436 foreach ( $headers as $tempheader ) {
437 if ( empty($tempheader) )
438 continue;
439
440 if ( false === strpos($tempheader, ':') ) {
441 list( , $response['code'], $response['message']) = explode(' ', $tempheader, 3);
442 continue;
443 }
444
445 list($key, $value) = explode(':', $tempheader, 2);
446
447 if ( !empty( $value ) ) {
448 $key = strtolower( $key );
449 if ( isset( $newheaders[$key] ) ) {
450 if ( !is_array($newheaders[$key]) )
451 $newheaders[$key] = array($newheaders[$key]);
452 $newheaders[$key][] = trim( $value );
453 } else {
454 $newheaders[$key] = trim( $value );
455 }
456 if ( 'set-cookie' == strtolower( $key ) )
457 $cookies[] = new WP_Http_Cookie( $value );
458 }
459 }
460
461 return array('response' => $response, 'headers' => $newheaders, 'cookies' => $cookies);
462 }
463
464 /**
465 * Takes the arguments for a ::request() and checks for the cookie array.
466 *
467 * If it's found, then it's assumed to contain WP_Http_Cookie objects, which are each parsed
468 * into strings and added to the Cookie: header (within the arguments array). Edits the array by
469 * reference.
470 *
471 * @access public
472 * @version 2.8.0
473 * @static
474 *
475 * @param array $r Full array of args passed into ::request()
476 */
477 function buildCookieHeader( &$r ) {
478 if ( ! empty($r['cookies']) ) {
479 $cookies_header = '';
480 foreach ( (array) $r['cookies'] as $cookie ) {
481 $cookies_header .= $cookie->getHeaderValue() . '; ';//Cross Site Scripting
482 }
483 $cookies_header = substr( $cookies_header, 0, -2 );
484 $r['headers']['cookie'] = $cookies_header;
485 }
486 }
487
488 /**
489 * Decodes chunk transfer-encoding, based off the HTTP 1.1 specification.
490 *
491 * Based off the HTTP http_encoding_dechunk function. Does not support UTF-8. Does not support
492 * returning footer headers. Shouldn't be too difficult to support it though.
493 *
494 * @todo Add support for footer chunked headers.
495 * @access public
496 * @since 2.7.0
497 * @static
498 *
499 * @param string $body Body content
500 * @return string Chunked decoded body on success or raw body on failure.
501 */
502 function chunkTransferDecode($body) {
503 $body = str_replace(array("\r\n", "\r"), "\n", $body);
504 // The body is not chunked encoding or is malformed.
505 if ( ! preg_match( '/^[0-9a-f]+(\s|\n)+/mi', trim($body) ) )
506 return $body;
507
508 $parsedBody = '';
509 //$parsedHeaders = array(); Unsupported
510
511 while ( true ) {
512 $hasChunk = (bool) preg_match( '/^([0-9a-f]+)(\s|\n)+/mi', $body, $match );
513
514 if ( $hasChunk ) {
515 if ( empty( $match[1] ) )
516 return $body;
517
518 $length = hexdec( $match[1] );
519 $chunkLength = strlen( $match[0] );
520
521 $strBody = substr($body, $chunkLength, $length);
522 $parsedBody .= $strBody;
523
524 $body = ltrim(str_replace(array($match[0], $strBody), '', $body), "\n");
525
526 if ( "0" == trim($body) )
527 return $parsedBody; // Ignore footer headers.
528 } else {
529 return $body;
530 }
531 }
532 }
533
534 /**
535 * Block requests through the proxy.
536 *
537 * Those who are behind a proxy and want to prevent access to certain hosts may do so. This will
538 * prevent plugins from working and core functionality, if you don't include api.wordpress.org.
539 *
540 * You block external URL requests by defining WP_HTTP_BLOCK_EXTERNAL as true in your wp-config.php
541 * file and this will only allow localhost and your blog to make requests. The constant
542 * 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 *
545 * @since 2.8.0
546 * @link http://core.trac.wordpress.org/ticket/8927 Allow preventing external requests.
547 *
548 * @param string $uri URI of url.
549 * @return bool True to block, false to allow.
550 */
551 function block_request($uri) {
552 // We don't need to block requests, because nothing is blocked.
553 if ( ! defined( 'WP_HTTP_BLOCK_EXTERNAL' ) || ! WP_HTTP_BLOCK_EXTERNAL )
554 return false;
555
556 // parse_url() only handles http, https type URLs, and will emit E_WARNING on failure.
557 // This will be displayed on blogs, which is not reasonable.
558 $check = @parse_url($uri);
559
560 /* Malformed URL, can not process, but this could mean ssl, so let through anyway.
561 *
562 * This isn't very security sound. There are instances where a hacker might attempt
563 * to bypass the proxy and this check. However, the reason for this behavior is that
564 * WordPress does not do any checking currently for non-proxy requests, so it is keeps with
565 * the default unsecure nature of the HTTP request.
566 */
567 if ( $check === false )
568 return false;
569
570 $home = parse_url( get_option('siteurl') );
571
572 // Don't block requests back to ourselves by default
573 if ( $check['host'] == 'localhost' || $check['host'] == $home['host'] )
574 return apply_filters('block_local_requests', false);
575
576 if ( !defined('WP_ACCESSIBLE_HOSTS') )
577 return true;
578
579 static $accessible_hosts;
580 if ( null == $accessible_hosts )
581 $accessible_hosts = preg_split('|,\s*|', WP_ACCESSIBLE_HOSTS);
582
583 return !in_array( $check['host'], $accessible_hosts ); //Inverse logic, If its in the array, then we can't access it.
584 }
585}
586
587/**
588 * HTTP request method uses fsockopen function to retrieve the url.
589 *
590 * This would be the preferred method, but the fsockopen implementation has the most overhead of all
591 * the HTTP transport implementations.
592 *
593 * @package WordPress
594 * @subpackage HTTP
595 * @since 2.7.0
596 */
597class WP_Http_Fsockopen {
598 /**
599 * Send a HTTP request to a URI using fsockopen().
600 *
601 * Does not support non-blocking mode.
602 *
603 * @see WP_Http::request For default options descriptions.
604 *
605 * @since 2.7
606 * @access public
607 * @param string $url URI resource.
608 * @param str|array $args Optional. Override the defaults.
609 * @return array 'headers', 'body', 'cookies' and 'response' keys.
610 */
611 function request($url, $args = array()) {
612 $defaults = array(
613 'method' => 'GET', 'timeout' => 5,
614 'redirection' => 5, 'httpversion' => '1.0',
615 'blocking' => true,
616 'headers' => array(), 'body' => null, 'cookies' => array()
617 );
618
619 $r = wp_parse_args( $args, $defaults );
620
621 if ( isset($r['headers']['User-Agent']) ) {
622 $r['user-agent'] = $r['headers']['User-Agent'];
623 unset($r['headers']['User-Agent']);
624 } else if( isset($r['headers']['user-agent']) ) {
625 $r['user-agent'] = $r['headers']['user-agent'];
626 unset($r['headers']['user-agent']);
627 }
628
629 // Construct Cookie: header if any cookies are set
630 WP_Http::buildCookieHeader( $r );
631
632 $iError = null; // Store error number
633 $strError = null; // Store error string
634
635 $arrURL = parse_url($url);
636
637 $fsockopen_host = $arrURL['host'];
638
639 $secure_transport = false;
640
641 if ( ! isset( $arrURL['port'] ) ) {
642 if ( ( $arrURL['scheme'] == 'ssl' || $arrURL['scheme'] == 'https' ) && extension_loaded('openssl') ) {
643 $fsockopen_host = "ssl://$fsockopen_host";
644 $arrURL['port'] = 443;
645 $secure_transport = true;
646 } else {
647 $arrURL['port'] = 80;
648 }
649 }
650
651 //fsockopen has issues with 'localhost' with IPv6 with certain versions of PHP, It attempts to connect to ::1,
652 // which fails when the server is not set up for it. For compatibility, always connect to the IPv4 address.
653 if ( 'localhost' == strtolower($fsockopen_host) )
654 $fsockopen_host = '127.0.0.1';
655
656 // There are issues with the HTTPS and SSL protocols that cause errors that can be safely
657 // ignored and should be ignored.
658 if ( true === $secure_transport )
659 $error_reporting = error_reporting(0);
660
661 $startDelay = time();
662
663 $proxy = new WP_HTTP_Proxy();
664
665 if ( !WP_DEBUG ) {
666 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
667 $handle = @fsockopen( $proxy->host(), $proxy->port(), $iError, $strError, $r['timeout'] );//Connection Handling
668 else
669 $handle = @fsockopen( $fsockopen_host, $arrURL['port'], $iError, $strError, $r['timeout'] );//Connection Handling
670 } else {
671 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
672 $handle = fsockopen( $proxy->host(), $proxy->port(), $iError, $strError, $r['timeout'] );//Connection Handling
673 else
674 $handle = fsockopen( $fsockopen_host, $arrURL['port'], $iError, $strError, $r['timeout'] );//Connection Handling
675 }
676
677 $endDelay = time();
678
679 // If the delay is greater than the timeout then fsockopen should't be used, because it will
680 // cause a long delay.
681 $elapseDelay = ($endDelay-$startDelay) > $r['timeout'];
682 if ( true === $elapseDelay )
683 add_option( 'disable_fsockopen', $endDelay, null, true );//Connection Handling
684
685 if ( false === $handle )
686 return new WP_Error('http_request_failed', $iError . ': ' . $strError);
687
688 $timeout = (int) floor( $r['timeout'] );
689 $utimeout = $timeout == $r['timeout'] ? 0 : 1000000 * $r['timeout'] % 1000000;
690 stream_set_timeout( $handle, $timeout, $utimeout );
691
692 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) //Some proxies require full URL in this field.
693 $requestPath = $url;
694 else
695 $requestPath = $arrURL['path'] . ( isset($arrURL['query']) ? '?' . $arrURL['query'] : '' );
696
697 if ( empty($requestPath) )
698 $requestPath .= '/';
699
700 $strHeaders = strtoupper($r['method']) . ' ' . $requestPath . ' HTTP/' . $r['httpversion'] . "\r\n";
701
702 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
703 $strHeaders .= 'Host: ' . $arrURL['host'] . ':' . $arrURL['port'] . "\r\n";
704 else
705 $strHeaders .= 'Host: ' . $arrURL['host'] . "\r\n";
706
707 if ( isset($r['user-agent']) )
708 $strHeaders .= 'User-agent: ' . $r['user-agent'] . "\r\n";
709
710 if ( is_array($r['headers']) ) {
711 foreach ( (array) $r['headers'] as $header => $headerValue )
712 $strHeaders .= $header . ': ' . $headerValue . "\r\n";//Cross Site Scripting
713 } else {
714 $strHeaders .= $r['headers'];
715 }
716
717 if ( $proxy->use_authentication() )
718 $strHeaders .= $proxy->authentication_header() . "\r\n";
719
720 $strHeaders .= "\r\n";
721
722 if ( ! is_null($r['body']) )
723 $strHeaders .= $r['body'];
724
725 fwrite($handle, $strHeaders);//Arbitrary file manipulations
726
727 if ( ! $r['blocking'] ) {
728 fclose($handle);
729 return array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() );
730 }
731
732 $strResponse = '';
733 while ( ! feof($handle) )
734 $strResponse .= fread($handle, 4096);//Arbitrary file disclosing
735
736 fclose($handle);
737
738 if ( true === $secure_transport )
739 error_reporting($error_reporting);
740
741 $process = WP_Http::processResponse($strResponse);
742 $arrHeaders = WP_Http::processHeaders($process['headers']);
743
744 // Is the response code within the 400 range?
745 if ( (int) $arrHeaders['response']['code'] >= 400 && (int) $arrHeaders['response']['code'] < 500 )
746 return new WP_Error('http_request_failed', $arrHeaders['response']['code'] . ': ' . $arrHeaders['response']['message']);
747
748 // If location is found, then assume redirect and redirect to location.
749 if ( 'HEAD' != $r['method'] && isset($arrHeaders['headers']['location']) ) {
750 if ( $r['redirection']-- > 0 ) {
751 return $this->request($arrHeaders['headers']['location'], $r);
752 } else {
753 return new WP_Error('http_request_failed', __('Too many redirects.'));
754 }
755 }
756
757 // If the body was chunk encoded, then decode it.
758 if ( ! empty( $process['body'] ) && isset( $arrHeaders['headers']['transfer-encoding'] ) && 'chunked' == $arrHeaders['headers']['transfer-encoding'] )
759 $process['body'] = WP_Http::chunkTransferDecode($process['body']);
760
761 if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($arrHeaders['headers']) )
762 $process['body'] = WP_Http_Encoding::decompress( $process['body'] );
763
764 return array('headers' => $arrHeaders['headers'], 'body' => $process['body'], 'response' => $arrHeaders['response'], 'cookies' => $arrHeaders['cookies']);
765 }
766
767 /**
768 * Whether this class can be used for retrieving an URL.
769 *
770 * @since 2.7.0
771 * @static
772 * @return boolean False means this class can not be used, true means it can.
773 */
774 function test( $args = array() ) {
775 if ( false !== ($option = get_option( 'disable_fsockopen' )) && time()-$option < 43200 ) // 12 hours
776 return false;
777
778 $is_ssl = isset($args['ssl']) && $args['ssl'];
779
780 if ( ! $is_ssl && function_exists( 'fsockopen' ) )
781 $use = true;
782 elseif ( $is_ssl && extension_loaded('openssl') && function_exists( 'fsockopen' ) )
783 $use = true;
784 else
785 $use = false;
786
787 return apply_filters('use_fsockopen_transport', $use, $args);
788 }
789}
790
791/**
792 * HTTP request method uses fopen function to retrieve the url.
793 *
794 * Requires PHP version greater than 4.3.0 for stream support. Does not allow for $context support,
795 * but should still be okay, to write the headers, before getting the response. Also requires that
796 * 'allow_url_fopen' to be enabled.
797 *
798 * @package WordPress
799 * @subpackage HTTP
800 * @since 2.7.0
801 */
802class WP_Http_Fopen {
803 /**
804 * Send a HTTP request to a URI using fopen().
805 *
806 * This transport does not support sending of headers and body, therefore should not be used in
807 * the instances, where there is a body and headers.
808 *
809 * Notes: Does not support non-blocking mode. Ignores 'redirection' option.
810 *
811 * @see WP_Http::retrieve For default options descriptions.
812 *
813 * @access public
814 * @since 2.7.0
815 *
816 * @param string $url URI resource.
817 * @param str|array $args Optional. Override the defaults.
818 * @return array 'headers', 'body', 'cookies' and 'response' keys.
819 */
820 function request($url, $args = array()) {
821 $defaults = array(
822 'method' => 'GET', 'timeout' => 5,
823 'redirection' => 5, 'httpversion' => '1.0',
824 'blocking' => true,
825 'headers' => array(), 'body' => null, 'cookies' => array()
826 );
827
828 $r = wp_parse_args( $args, $defaults );
829
830 $arrURL = parse_url($url);
831
832 if ( false === $arrURL )
833 return new WP_Error('http_request_failed', sprintf(__('Malformed URL: %s'), $url));
834
835 if ( 'http' != $arrURL['scheme'] && 'https' != $arrURL['scheme'] )
836 $url = str_replace($arrURL['scheme'], 'http', $url);
837
838 if ( is_null( $r['headers'] ) )
839 $r['headers'] = array();
840
841 if ( is_string($r['headers']) ) {
842 $processedHeaders = WP_Http::processHeaders($r['headers']);
843 $r['headers'] = $processedHeaders['headers'];
844 }
845
846 $initial_user_agent = ini_get('user_agent');
847
848 if ( !empty($r['headers']) && is_array($r['headers']) ) {
849 $user_agent_extra_headers = '';
850 foreach ( $r['headers'] as $header => $value )
851 $user_agent_extra_headers .= "\r\n$header: $value";//Cross Site Scripting
852 @ini_set('user_agent', $r['user-agent'] . $user_agent_extra_headers);
853 } else {
854 @ini_set('user_agent', $r['user-agent']);
855 }
856
857 if ( !WP_DEBUG )
858 $handle = @fopen($url, 'r');
859 else
860 $handle = fopen($url, 'r');
861
862 if (! $handle)
863 return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url));
864
865 $timeout = (int) floor( $r['timeout'] );
866 $utimeout = $timeout == $r['timeout'] ? 0 : 1000000 * $r['timeout'] % 1000000;
867 stream_set_timeout( $handle, $timeout, $utimeout );
868
869 if ( ! $r['blocking'] ) {
870 fclose($handle);
871 @ini_set('user_agent', $initial_user_agent); //Clean up any extra headers added
872 return array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() );
873 }
874
875 $strResponse = '';
876 while ( ! feof($handle) )
877 $strResponse .= fread($handle, 4096);//Arbitrary file disclosing
878
879 if ( function_exists('stream_get_meta_data') ) {
880 $meta = stream_get_meta_data($handle);
881
882 $theHeaders = $meta['wrapper_data'];
883 if ( isset( $meta['wrapper_data']['headers'] ) )
884 $theHeaders = $meta['wrapper_data']['headers'];
885 } else {
886 //$http_response_header is a PHP reserved variable which is set in the current-scope when using the HTTP Wrapper
887 //see http://php.oregonstate.edu/manual/en/reserved.variables.httpresponseheader.php
888 $theHeaders = $http_response_header;
889 }
890
891 fclose($handle);
892
893 @ini_set('user_agent', $initial_user_agent); //Clean up any extra headers added
894
895 $processedHeaders = WP_Http::processHeaders($theHeaders);
896
897 if ( ! empty( $strResponse ) && isset( $processedHeaders['headers']['transfer-encoding'] ) && 'chunked' == $processedHeaders['headers']['transfer-encoding'] )
898 $strResponse = WP_Http::chunkTransferDecode($strResponse);
899
900 if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($processedHeaders['headers']) )
901 $strResponse = WP_Http_Encoding::decompress( $strResponse );
902
903 return array('headers' => $processedHeaders['headers'], 'body' => $strResponse, 'response' => $processedHeaders['response'], 'cookies' => $processedHeaders['cookies']);
904 }
905
906 /**
907 * Whether this class can be used for retrieving an URL.
908 *
909 * @since 2.7.0
910 * @static
911 * @return boolean False means this class can not be used, true means it can.
912 */
913 function test($args = array()) {
914 if ( ! function_exists('fopen') || (function_exists('ini_get') && true != ini_get('allow_url_fopen')) )
915 return false;
916
917 if ( isset($args['method']) && 'HEAD' == $args['method'] ) //This transport cannot make a HEAD request
918 return false;
919
920 $use = true;
921 //PHP does not verify SSL certs, We can only make a request via this transports if SSL Verification is turned off.
922 $is_ssl = isset($args['ssl']) && $args['ssl'];
923 if ( $is_ssl ) {
924 $is_local = isset($args['local']) && $args['local'];
925 $ssl_verify = isset($args['sslverify']) && $args['sslverify'];
926 if ( $is_local && true != apply_filters('https_local_ssl_verify', true) )
927 $use = true;
928 elseif ( !$is_local && true != apply_filters('https_ssl_verify', true) )
929 $use = true;
930 elseif ( !$ssl_verify )
931 $use = true;
932 else
933 $use = false;
934 }
935
936 return apply_filters('use_fopen_transport', $use, $args);
937 }
938}
939
940/**
941 * HTTP request method uses Streams to retrieve the url.
942 *
943 * Requires PHP 5.0+ and uses fopen with stream context. Requires that 'allow_url_fopen' PHP setting
944 * to be enabled.
945 *
946 * Second preferred method for getting the URL, for PHP 5.
947 *
948 * @package WordPress
949 * @subpackage HTTP
950 * @since 2.7.0
951 */
952class WP_Http_Streams {
953 /**
954 * Send a HTTP request to a URI using streams with fopen().
955 *
956 * @access public
957 * @since 2.7.0
958 *
959 * @param string $url
960 * @param str|array $args Optional. Override the defaults.
961 * @return array 'headers', 'body', 'cookies' and 'response' keys.
962 */
963 function request($url, $args = array()) {
964 $defaults = array(
965 'method' => 'GET', 'timeout' => 5,
966 'redirection' => 5, 'httpversion' => '1.0',
967 'blocking' => true,
968 'headers' => array(), 'body' => null, 'cookies' => array()
969 );
970
971 $r = wp_parse_args( $args, $defaults );
972
973 if ( isset($r['headers']['User-Agent']) ) {
974 $r['user-agent'] = $r['headers']['User-Agent'];
975 unset($r['headers']['User-Agent']);
976 } else if( isset($r['headers']['user-agent']) ) {
977 $r['user-agent'] = $r['headers']['user-agent'];
978 unset($r['headers']['user-agent']);
979 }
980
981 // Construct Cookie: header if any cookies are set
982 WP_Http::buildCookieHeader( $r );
983
984 $arrURL = parse_url($url);
985
986 if ( false === $arrURL )
987 return new WP_Error('http_request_failed', sprintf(__('Malformed URL: %s'), $url));
988
989 if ( 'http' != $arrURL['scheme'] && 'https' != $arrURL['scheme'] )
990 $url = preg_replace('|^' . preg_quote($arrURL['scheme'], '|') . '|', 'http', $url);
991
992 // Convert Header array to string.
993 $strHeaders = '';
994 if ( is_array( $r['headers'] ) )
995 foreach ( $r['headers'] as $name => $value )
996 $strHeaders .= "{$name}: $value\r\n";
997 else if ( is_string( $r['headers'] ) )
998 $strHeaders = $r['headers'];
999
1000 $is_local = isset($args['local']) && $args['local'];
/var/www/wordpress/wp-includes/class-IXR.php
/var/www/wordpress/wp-includes/class-json.php
/var/www/wordpress/wp-includes/class-oembed.php
/var/www/wordpress/wp-includes/class-phpass.php
/var/www/wordpress/wp-includes/class-phpmailer.php
/var/www/wordpress/wp-includes/class-pop3.php
/var/www/wordpress/wp-includes/class-simplepie.php
/var/www/wordpress/wp-includes/class-smtp.php
/var/www/wordpress/wp-includes/class-snoopy.php
/var/www/wordpress/wp-includes/class.wp-dependencies.php
/var/www/wordpress/wp-includes/class.wp-scripts.php
/var/www/wordpress/wp-includes/class.wp-styles.php
/var/www/wordpress/wp-includes/classes.php
/var/www/wordpress/wp-includes/comment-template.php
/var/www/wordpress/wp-includes/comment.php
/var/www/wordpress/wp-includes/compat.php
/var/www/wordpress/wp-includes/cron.php
/var/www/wordpress/wp-includes/default-constants.php
/var/www/wordpress/wp-includes/default-embeds.php
/var/www/wordpress/wp-includes/default-filters.php
/var/www/wordpress/wp-includes/default-widgets.php
/var/www/wordpress/wp-includes/deprecated.php
/var/www/wordpress/wp-includes/feed-atom-comments.php
/var/www/wordpress/wp-includes/feed-atom.php
/var/www/wordpress/wp-includes/feed-rdf.php
/var/www/wordpress/wp-includes/feed-rss.php
/var/www/wordpress/wp-includes/feed-rss2-comments.php
/var/www/wordpress/wp-includes/feed-rss2.php
/var/www/wordpress/wp-includes/feed.php
/var/www/wordpress/wp-includes/formatting.php
/var/www/wordpress/wp-includes/functions.php
/var/www/wordpress/wp-includes/functions.wp-scripts.php
/var/www/wordpress/wp-includes/functions.wp-styles.php
/var/www/wordpress/wp-includes/general-template.php
/var/www/wordpress/wp-includes/http.php
/var/www/wordpress/wp-includes/kses.php
/var/www/wordpress/wp-includes/l10n.php
/var/www/wordpress/wp-includes/link-template.php
/var/www/wordpress/wp-includes/load.php
/var/www/wordpress/wp-includes/locale.php
/var/www/wordpress/wp-includes/media.php
/var/www/wordpress/wp-includes/meta.php
/var/www/wordpress/wp-includes/ms-blogs.php
/var/www/wordpress/wp-includes/ms-default-constants.php
/var/www/wordpress/wp-includes/ms-default-filters.php
/var/www/wordpress/wp-includes/ms-deprecated.php
/var/www/wordpress/wp-includes/ms-files.php
/var/www/wordpress/wp-includes/ms-functions.php
/var/www/wordpress/wp-includes/ms-load.php
/var/www/wordpress/wp-includes/ms-settings.php
/var/www/wordpress/wp-includes/nav-menu-template.php
/var/www/wordpress/wp-includes/nav-menu.php
/var/www/wordpress/wp-includes/pluggable-deprecated.php
/var/www/wordpress/wp-includes/pluggable.php
/var/www/wordpress/wp-includes/plugin.php
/var/www/wordpress/wp-includes/post-template.php
/var/www/wordpress/wp-includes/post-thumbnail-template.php
/var/www/wordpress/wp-includes/post.php
/var/www/wordpress/wp-includes/query.php
/var/www/wordpress/wp-includes/registration-functions.php
/var/www/wordpress/wp-includes/registration.php
/var/www/wordpress/wp-includes/rewrite.php
/var/www/wordpress/wp-includes/rss-functions.php
/var/www/wordpress/wp-includes/rss.php
/var/www/wordpress/wp-includes/script-loader.php
/var/www/wordpress/wp-includes/shortcodes.php
/var/www/wordpress/wp-includes/taxonomy.php
/var/www/wordpress/wp-includes/template-loader.php
/var/www/wordpress/wp-includes/theme.php
/var/www/wordpress/wp-includes/update.php
/var/www/wordpress/wp-includes/user.php
/var/www/wordpress/wp-includes/vars.php
/var/www/wordpress/wp-includes/version.php
/var/www/wordpress/wp-includes/widgets.php
/var/www/wordpress/wp-includes/wp-db.php
/var/www/wordpress/wp-includes/wp-diff.php
/var/www/wordpress/index.php
/var/www/wordpress/wp-activate.php
/var/www/wordpress/wp-app.php
/var/www/wordpress/wp-atom.php
/var/www/wordpress/wp-blog-header.php
/var/www/wordpress/wp-comments-post.php
/var/www/wordpress/wp-commentsrss2.php
/var/www/wordpress/wp-config-sample.php
/var/www/wordpress/wp-cron.php
/var/www/wordpress/wp-feed.php
/var/www/wordpress/wp-links-opml.php
/var/www/wordpress/wp-load.php
/var/www/wordpress/wp-login.php
/var/www/wordpress/wp-mail.php
/var/www/wordpress/wp-pass.php
/var/www/wordpress/wp-rdf.php
/var/www/wordpress/wp-register.php
/var/www/wordpress/wp-rss.php
/var/www/wordpress/wp-rss2.php
/var/www/wordpress/wp-settings.php
/var/www/wordpress/wp-signup.php
/var/www/wordpress/wp-trackback.php
/var/www/wordpress/xmlrpc.php