- * PHP4 style Constructor - Calls PHP5 Style Constructor
- *
- * @since 2.7.0
- * @return WP_Http
- */
- function WP_Http() {
- $this->__construct();
- }
-
- /**
- * PHP5 style Constructor - Set up available transport if not available.
- *
- * PHP4 does not have the 'self' keyword and since WordPress supports PHP4, the class needs to
- * be used for the static call. The transport are set up to save time and will only be created
- * once. This class can be created many times without having to go through the step of finding
- * which transports are available.
- *
- * @since 2.7.0
- * @return WP_Http
- */
- function __construct() {
- WP_Http::_getTransport();
- WP_Http::_postTransport();
- }
-
- /**
- * Tests the WordPress HTTP objects for an object to use and returns it.
- *
- * Tests all of the objects and returns the object that passes. Also caches that object to be
- * used later.
- *
- * The order for the GET/HEAD requests are HTTP Extension, cURL, Streams, Fopen, and finally
- * Fsockopen. fsockopen() is used last, because it has the most overhead in its implementation.
- * There isn't any real way around it, since redirects have to be supported, much the same way
- * the other transports also handle redirects.
- *
- * There are currently issues with "localhost" not resolving correctly with DNS. This may cause
- * an error "failed to open stream: A connection attempt failed because the connected party did
- * not properly respond after a period of time, or established connection failed because [the]
- * connected host has failed to respond."
- *
- * @since 2.7.0
- * @access private
- *
- * @param array $args Request args, default us an empty array
- * @return object|null Null if no transports are available, HTTP transport object.
- */
- function &_getTransport( $args = array() ) {
- static $working_transport, $blocking_transport, $nonblocking_transport;
-
- if ( is_null($working_transport) ) {
- if ( true === WP_Http_ExtHttp::test($args) ) {
- $working_transport['exthttp'] = new WP_Http_ExtHttp();
- $blocking_transport[] = &$working_transport['exthttp'];
- } else if ( true === WP_Http_Curl::test($args) ) {
- $working_transport['curl'] = new WP_Http_Curl();
- $blocking_transport[] = &$working_transport['curl'];
- } else if ( true === WP_Http_Streams::test($args) ) {
- $working_transport['streams'] = new WP_Http_Streams();
- $blocking_transport[] = &$working_transport['streams'];
- } else if ( true === WP_Http_Fopen::test($args) ) {
- $working_transport['fopen'] = new WP_Http_Fopen();
- $blocking_transport[] = &$working_transport['fopen'];
- } else if ( true === WP_Http_Fsockopen::test($args) ) {
- $working_transport['fsockopen'] = new WP_Http_Fsockopen();
- $blocking_transport[] = &$working_transport['fsockopen'];
- }
-
- foreach ( array('curl', 'streams', 'fopen', 'fsockopen', 'exthttp') as $transport ) {
- if ( isset($working_transport[$transport]) )
- $nonblocking_transport[] = &$working_transport[$transport];
- }
- }
-
- do_action( 'http_transport_get_debug', $working_transport, $blocking_transport, $nonblocking_transport );
-
- if ( isset($args['blocking']) && !$args['blocking'] )
- return $nonblocking_transport;
- else
- return $blocking_transport;
- }
-
- /**
- * Tests the WordPress HTTP objects for an object to use and returns it.
- *
- * Tests all of the objects and returns the object that passes. Also caches
- * that object to be used later. This is for posting content to a URL and
- * is used when there is a body. The plain Fopen Transport can not be used
- * to send content, but the streams transport can. This is a limitation that
- * is addressed here, by just not including that transport.