예제 #1
0
 function __construct()
 {
     $this->processdone = FALSE;
     $this->genesis = FALSE;
     //$this->reorder      = FALSE;
     $this->is_new = FALSE;
     $this->encoding = WP_Http_Encoding::is_available();
     $this->menuName = CHLD_THM_CFG_MENU;
     // backward compatability for plugins extension
     $this->is_post = 'POST' == $_SERVER['REQUEST_METHOD'];
     $this->is_get = 'GET' == $_SERVER['REQUEST_METHOD'];
     $this->is_debug = get_option(CHLD_THM_CFG_OPTIONS . '_debug');
     $this->debug = '';
     $this->errors = array();
 }
예제 #2
0
파일: http.php 프로젝트: steveh/wordpress
 /**
  * Send a HTTP request to a URI.
  *
  * The body and headers are part of the arguments. The 'body' argument is for the body and will
  * accept either a string or an array. The 'headers' argument should be an array, but a string
  * is acceptable. If the 'body' argument is an array, then it will automatically be escaped
  * using http_build_query().
  *
  * The only URI that are supported in the HTTP Transport implementation are the HTTP and HTTPS
  * protocols. HTTP and HTTPS are assumed so the server might not know how to handle the send
  * headers. Other protocols are unsupported and most likely will fail.
  *
  * The defaults are 'method', 'timeout', 'redirection', 'httpversion', 'blocking' and
  * 'user-agent'.
  *
  * Accepted 'method' values are 'GET', 'POST', and 'HEAD', some transports technically allow
  * others, but should not be assumed. The 'timeout' is used to sent how long the connection
  * should stay open before failing when no response. 'redirection' is used to track how many
  * redirects were taken and used to sent the amount for other transports, but not all transports
  * accept setting that value.
  *
  * The 'httpversion' option is used to sent the HTTP version and accepted values are '1.0', and
  * '1.1' and should be a string. Version 1.1 is not supported, because of chunk response. The
  * 'user-agent' option is the user-agent and is used to replace the default user-agent, which is
  * 'WordPress/WP_Version', where WP_Version is the value from $wp_version.
  *
  * 'blocking' is the default, which is used to tell the transport, whether it should halt PHP
  * while it performs the request or continue regardless. Actually, that isn't entirely correct.
  * Blocking mode really just means whether the fread should just pull what it can whenever it
  * gets bytes or if it should wait until it has enough in the buffer to read or finishes reading
  * the entire content. It doesn't actually always mean that PHP will continue going after making
  * the request.
  *
  * @access public
  * @since 2.7.0
  * @todo Refactor this code. The code in this method extends the scope of its original purpose
  *		and should be refactored to allow for cleaner abstraction and reduce duplication of the
  *		code. One suggestion is to create a class specifically for the arguments, however
  *		preliminary refactoring to this affect has affect more than just the scope of the
  *		arguments. Something to ponder at least.
  *
  * @param string $url URI resource.
  * @param str|array $args Optional. Override the defaults.
  * @return array containing 'headers', 'body', 'response', 'cookies'
  */
 function request($url, $args = array())
 {
     global $wp_version;
     $defaults = array('method' => 'GET', 'timeout' => apply_filters('http_request_timeout', 5), 'redirection' => apply_filters('http_request_redirection_count', 5), 'httpversion' => apply_filters('http_request_version', '1.0'), 'user-agent' => apply_filters('http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')), 'blocking' => true, 'headers' => array(), 'cookies' => array(), 'body' => null, 'compress' => false, 'decompress' => true, 'sslverify' => true);
     $r = wp_parse_args($args, $defaults);
     $r = apply_filters('http_request_args', $r, $url);
     // Allow plugins to short-circuit the request
     $pre = apply_filters('pre_http_request', false, $r, $url);
     if (false !== $pre) {
         return $pre;
     }
     $arrURL = parse_url($url);
     if ($this->block_request($url)) {
         return new WP_Error('http_request_failed', __('User has blocked requests through HTTP.'));
     }
     // Determine if this is a https call and pass that on to the transport functions
     // so that we can blacklist the transports that do not support ssl verification
     $r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl';
     // Determine if this request is to OUR install of WordPress
     $homeURL = parse_url(get_bloginfo('url'));
     $r['local'] = $homeURL['host'] == $arrURL['host'] || 'localhost' == $arrURL['host'];
     unset($homeURL);
     if (is_null($r['headers'])) {
         $r['headers'] = array();
     }
     if (!is_array($r['headers'])) {
         $processedHeaders = WP_Http::processHeaders($r['headers']);
         $r['headers'] = $processedHeaders['headers'];
     }
     if (isset($r['headers']['User-Agent'])) {
         $r['user-agent'] = $r['headers']['User-Agent'];
         unset($r['headers']['User-Agent']);
     }
     if (isset($r['headers']['user-agent'])) {
         $r['user-agent'] = $r['headers']['user-agent'];
         unset($r['headers']['user-agent']);
     }
     // Construct Cookie: header if any cookies are set
     WP_Http::buildCookieHeader($r);
     if (WP_Http_Encoding::is_available()) {
         $r['headers']['Accept-Encoding'] = WP_Http_Encoding::accept_encoding();
     }
     if (empty($r['body'])) {
         // Some servers fail when sending content without the content-length header being set.
         // Also, to fix another bug, we only send when doing POST and PUT and the content-length
         // header isn't already set.
         if (($r['method'] == 'POST' || $r['method'] == 'PUT') && !isset($r['headers']['Content-Length'])) {
             $r['headers']['Content-Length'] = 0;
         }
         // The method is ambiguous, because we aren't talking about HTTP methods, the "get" in
         // this case is simply that we aren't sending any bodies and to get the transports that
         // don't support sending bodies along with those which do.
         $transports = WP_Http::_getTransport($r);
     } else {
         if (is_array($r['body']) || is_object($r['body'])) {
             if (!version_compare(phpversion(), '5.1.2', '>=')) {
                 $r['body'] = _http_build_query($r['body'], null, '&');
             } else {
                 $r['body'] = http_build_query($r['body'], null, '&');
             }
             $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset');
             $r['headers']['Content-Length'] = strlen($r['body']);
         }
         if (!isset($r['headers']['Content-Length']) && !isset($r['headers']['content-length'])) {
             $r['headers']['Content-Length'] = strlen($r['body']);
         }
         // The method is ambiguous, because we aren't talking about HTTP methods, the "post" in
         // this case is simply that we are sending HTTP body and to get the transports that do
         // support sending the body. Not all do, depending on the limitations of the PHP core
         // limitations.
         $transports = WP_Http::_postTransport($r);
     }
     do_action('http_api_debug', $transports, 'transports_list');
     $response = array('headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array());
     foreach ((array) $transports as $transport) {
         $response = $transport->request($url, $r);
         do_action('http_api_debug', $response, 'response', get_class($transport));
         if (!is_wp_error($response)) {
             return apply_filters('http_response', $response, $r, $url);
         }
     }
     return $response;
 }
예제 #3
0
파일: http.php 프로젝트: blowery/wordpress
 /**
  * Send a HTTP request to a URI.
  *
  * The body and headers are part of the arguments. The 'body' argument is
  * for the body and will accept either a string or an array. The 'headers'
  * argument should be an array, but a string is acceptable. If the 'body'
  * argument is an array, then it will automatically be escaped using
  * http_build_query().
  *
  * The only URI that are supported in the HTTP Transport implementation are
  * the HTTP and HTTPS protocols. HTTP and HTTPS are assumed so the server
  * might not know how to handle the send headers. Other protocols are
  * unsupported and most likely will fail.
  *
  * The defaults are 'method', 'timeout', 'redirection', 'httpversion',
  * 'blocking' and 'user-agent'.
  *
  * Accepted 'method' values are 'GET', 'POST', and 'HEAD', some transports
  * technically allow others, but should not be assumed. The 'timeout' is
  * used to sent how long the connection should stay open before failing when
  * no response. 'redirection' is used to track how many redirects were taken
  * and used to sent the amount for other transports, but not all transports
  * accept setting that value.
  *
  * The 'httpversion' option is used to sent the HTTP version and accepted
  * values are '1.0', and '1.1' and should be a string. Version 1.1 is not
  * supported, because of chunk response. The 'user-agent' option is the
  * user-agent and is used to replace the default user-agent, which is
  * 'WordPress/WP_Version', where WP_Version is the value from $wp_version.
  *
  * 'blocking' is the default, which is used to tell the transport, whether
  * it should halt PHP while it performs the request or continue regardless.
  * Actually, that isn't entirely correct. Blocking mode really just means
  * whether the fread should just pull what it can whenever it gets bytes or
  * if it should wait until it has enough in the buffer to read or finishes
  * reading the entire content. It doesn't actually always mean that PHP will
  * continue going after making the request.
  *
  * @access public
  * @since 2.7.0
  *
  * @param string $url URI resource.
  * @param str|array $args Optional. Override the defaults.
  * @return boolean
  */
 function request($url, $args = array())
 {
     global $wp_version;
     $defaults = array('method' => 'GET', 'timeout' => apply_filters('http_request_timeout', 5), 'redirection' => apply_filters('http_request_redirection_count', 5), 'httpversion' => apply_filters('http_request_version', '1.0'), 'user-agent' => apply_filters('http_headers_useragent', 'WordPress/' . $wp_version), 'blocking' => true, 'headers' => array(), 'body' => null, 'compress' => false, 'decompress' => true);
     $r = wp_parse_args($args, $defaults);
     $r = apply_filters('http_request_args', $r, $url);
     if (is_null($r['headers'])) {
         $r['headers'] = array();
     }
     if (!is_array($r['headers'])) {
         $processedHeaders = WP_Http::processHeaders($r['headers']);
         $r['headers'] = $processedHeaders['headers'];
     }
     if (isset($r['headers']['User-Agent'])) {
         $r['user-agent'] = $r['headers']['User-Agent'];
         unset($r['headers']['User-Agent']);
     }
     if (isset($r['headers']['user-agent'])) {
         $r['user-agent'] = $r['headers']['user-agent'];
         unset($r['headers']['user-agent']);
     }
     if (WP_Http_Encoding::is_available()) {
         $r['headers']['Accept-Encoding'] = WP_Http_Encoding::accept_encoding();
     }
     if (is_null($r['body'])) {
         // Some servers fail when sending content without the content-length
         // header being set.
         $r['headers']['Content-Length'] = 0;
         $transports = WP_Http::_getTransport($r);
     } else {
         if (is_array($r['body']) || is_object($r['body'])) {
             $r['body'] = http_build_query($r['body'], null, '&');
             $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset');
             $r['headers']['Content-Length'] = strlen($r['body']);
         }
         if (!isset($r['headers']['Content-Length']) && !isset($r['headers']['content-length'])) {
             $r['headers']['Content-Length'] = strlen($r['body']);
         }
         $transports = WP_Http::_postTransport($r);
     }
     if (has_action('http_api_debug')) {
         do_action('http_api_debug', $transports, 'transports_list');
     }
     $response = array('headers' => array(), 'body' => '', 'response' => array('code', 'message'));
     foreach ((array) $transports as $transport) {
         $response = $transport->request($url, $r);
         if (has_action('http_api_debug')) {
             do_action('http_api_debug', $response, 'response', get_class($transport));
         }
         if (!is_wp_error($response)) {
             return $response;
         }
     }
     return $response;
 }
예제 #4
0
 /**
  * What encoding types to accept and their priority values.
  *
  * @since 2.8.0
  *
  * @return string Types of encoding to accept.
  */
 public static function accept_encoding($url, $args)
 {
     $type = array();
     $compression_enabled = WP_Http_Encoding::is_available();
     if (!$args['decompress']) {
         // Decompression specifically disabled.
         $compression_enabled = false;
     } elseif ($args['stream']) {
         // Disable when streaming to file.
         $compression_enabled = false;
     } elseif (isset($args['limit_response_size'])) {
         // If only partial content is being requested, we won't be able to decompress it.
         $compression_enabled = false;
     }
     if ($compression_enabled) {
         if (function_exists('gzinflate')) {
             $type[] = 'deflate;q=1.0';
         }
         if (function_exists('gzuncompress')) {
             $type[] = 'compress;q=0.5';
         }
         if (function_exists('gzdecode')) {
             $type[] = 'gzip;q=0.5';
         }
     }
     /**
      * Filter the allowed encoding types.
      *
      * @since 3.6.0
      *
      * @param array  $type Encoding types allowed. Accepts 'gzinflate',
      *                     'gzuncompress', 'gzdecode'.
      * @param string $url  URL of the HTTP request.
      * @param array  $args HTTP request arguments.
      */
     $type = apply_filters('wp_http_accept_encoding', $type, $url, $args);
     return implode(', ', $type);
 }
예제 #5
0
 /**
  * Send a HTTP request to a URI.
  *
  * The body and headers are part of the arguments. The 'body' argument is for the body and will
  * accept either a string or an array. The 'headers' argument should be an array, but a string
  * is acceptable. If the 'body' argument is an array, then it will automatically be escaped
  * using http_build_query().
  *
  * The only URI that are supported in the HTTP Transport implementation are the HTTP and HTTPS
  * protocols. HTTP and HTTPS are assumed so the server might not know how to handle the send
  * headers. Other protocols are unsupported and most likely will fail.
  *
  * The defaults are 'method', 'timeout', 'redirection', 'httpversion', 'blocking' and
  * 'user-agent'.
  *
  * Accepted 'method' values are 'GET', 'POST', and 'HEAD', some transports technically allow
  * others, but should not be assumed. The 'timeout' is used to sent how long the connection
  * should stay open before failing when no response. 'redirection' is used to track how many
  * redirects were taken and used to sent the amount for other transports, but not all transports
  * accept setting that value.
  *
  * The 'httpversion' option is used to sent the HTTP version and accepted values are '1.0', and
  * '1.1' and should be a string. Version 1.1 is not supported, because of chunk response. The
  * 'user-agent' option is the user-agent and is used to replace the default user-agent, which is
  * 'WordPress/WP_Version', where WP_Version is the value from $wp_version.
  *
  * 'blocking' is the default, which is used to tell the transport, whether it should halt PHP
  * while it performs the request or continue regardless. Actually, that isn't entirely correct.
  * Blocking mode really just means whether the fread should just pull what it can whenever it
  * gets bytes or if it should wait until it has enough in the buffer to read or finishes reading
  * the entire content. It doesn't actually always mean that PHP will continue going after making
  * the request.
  *
  * @access public
  * @since 2.7.0
  * @todo Refactor this code. The code in this method extends the scope of its original purpose
  *		and should be refactored to allow for cleaner abstraction and reduce duplication of the
  *		code. One suggestion is to create a class specifically for the arguments, however
  *		preliminary refactoring to this affect has affect more than just the scope of the
  *		arguments. Something to ponder at least.
  *
  * @param string $url URI resource.
  * @param str|array $args Optional. Override the defaults.
  * @return array|object Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
  */
 function request($url, $args = array())
 {
     global $wp_version;
     $defaults = array('method' => 'GET', 'timeout' => apply_filters('http_request_timeout', 5), 'redirection' => apply_filters('http_request_redirection_count', 5), 'httpversion' => apply_filters('http_request_version', '1.0'), 'user-agent' => apply_filters('http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')), 'blocking' => true, 'headers' => array(), 'cookies' => array(), 'body' => null, 'compress' => false, 'decompress' => true, 'sslverify' => true, 'stream' => false, 'filename' => null);
     // Pre-parse for the HEAD checks.
     $args = wp_parse_args($args);
     // By default, Head requests do not cause redirections.
     if (isset($args['method']) && 'HEAD' == $args['method']) {
         $defaults['redirection'] = 0;
     }
     $r = wp_parse_args($args, $defaults);
     $r = apply_filters('http_request_args', $r, $url);
     // Certain classes decrement this, store a copy of the original value for loop purposes.
     $r['_redirection'] = $r['redirection'];
     // Allow plugins to short-circuit the request
     $pre = apply_filters('pre_http_request', false, $r, $url);
     if (false !== $pre) {
         return $pre;
     }
     $arrURL = parse_url($url);
     if (empty($url) || empty($arrURL['scheme'])) {
         return new WP_Error('http_request_failed', __('A valid URL was not provided.'));
     }
     if ($this->block_request($url)) {
         return new WP_Error('http_request_failed', __('User has blocked requests through HTTP.'));
     }
     // Determine if this is a https call and pass that on to the transport functions
     // so that we can blacklist the transports that do not support ssl verification
     $r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl';
     // Determine if this request is to OUR install of WordPress
     $homeURL = parse_url(get_bloginfo('url'));
     $r['local'] = $homeURL['host'] == $arrURL['host'] || 'localhost' == $arrURL['host'];
     unset($homeURL);
     // If we are streaming to a file but no filename was given drop it in the WP temp dir
     // and pick it's name using the basename of the $url
     if ($r['stream'] && empty($r['filename'])) {
         $r['filename'] = get_temp_dir() . basename($url);
     }
     // Force some settings if we are streaming to a file and check for existence and perms of destination directory
     if ($r['stream']) {
         $r['blocking'] = true;
         if (!is_writable(dirname($r['filename']))) {
             return new WP_Error('http_request_failed', __('Destination directory for file streaming does not exist or is not writable.'));
         }
     }
     if (is_null($r['headers'])) {
         $r['headers'] = array();
     }
     if (!is_array($r['headers'])) {
         $processedHeaders = WP_Http::processHeaders($r['headers']);
         $r['headers'] = $processedHeaders['headers'];
     }
     if (isset($r['headers']['User-Agent'])) {
         $r['user-agent'] = $r['headers']['User-Agent'];
         unset($r['headers']['User-Agent']);
     }
     if (isset($r['headers']['user-agent'])) {
         $r['user-agent'] = $r['headers']['user-agent'];
         unset($r['headers']['user-agent']);
     }
     // Construct Cookie: header if any cookies are set
     WP_Http::buildCookieHeader($r);
     if (WP_Http_Encoding::is_available()) {
         $r['headers']['Accept-Encoding'] = WP_Http_Encoding::accept_encoding();
     }
     if (empty($r['body'])) {
         $r['body'] = null;
         // Some servers fail when sending content without the content-length header being set.
         // Also, to fix another bug, we only send when doing POST and PUT and the content-length
         // header isn't already set.
         if (($r['method'] == 'POST' || $r['method'] == 'PUT') && !isset($r['headers']['Content-Length'])) {
             $r['headers']['Content-Length'] = 0;
         }
     } else {
         if (is_array($r['body']) || is_object($r['body'])) {
             $r['body'] = http_build_query($r['body'], null, '&');
             $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset');
             $r['headers']['Content-Length'] = strlen($r['body']);
         }
         if (!isset($r['headers']['Content-Length']) && !isset($r['headers']['content-length'])) {
             $r['headers']['Content-Length'] = strlen($r['body']);
         }
     }
     return $this->_dispatch_request($url, $r);
 }
예제 #6
0
	/**
	 * Send a HTTP request to a URI.
	 *
	 * The body and headers are part of the arguments. The 'body' argument is for the body and will
	 * accept either a string or an array. The 'headers' argument should be an array, but a string
	 * is acceptable. If the 'body' argument is an array, then it will automatically be escaped
	 * using http_build_query().
	 *
	 * The only URI that are supported in the HTTP Transport implementation are the HTTP and HTTPS
	 * protocols. HTTP and HTTPS are assumed so the server might not know how to handle the send
	 * headers. Other protocols are unsupported and most likely will fail.
	 *
	 * The defaults are 'method', 'timeout', 'redirection', 'httpversion', 'blocking' and
	 * 'user-agent'.
	 *
	 * Accepted 'method' values are 'GET', 'POST', and 'HEAD', some transports technically allow
	 * others, but should not be assumed. The 'timeout' is used to sent how long the connection
	 * should stay open before failing when no response. 'redirection' is used to track how many
	 * redirects were taken and used to sent the amount for other transports, but not all transports
	 * accept setting that value.
	 *
	 * The 'httpversion' option is used to sent the HTTP version and accepted values are '1.0', and
	 * '1.1' and should be a string. Version 1.1 is not supported, because of chunk response. The
	 * 'user-agent' option is the user-agent and is used to replace the default user-agent, which is
	 * 'WordPress/WP_Version', where WP_Version is the value from $wp_version.
	 *
	 * 'blocking' is the default, which is used to tell the transport, whether it should halt PHP
	 * while it performs the request or continue regardless. Actually, that isn't entirely correct.
	 * Blocking mode really just means whether the fread should just pull what it can whenever it
	 * gets bytes or if it should wait until it has enough in the buffer to read or finishes reading
	 * the entire content. It doesn't actually always mean that PHP will continue going after making
	 * the request.
	 *
	 * @access public
	 * @since 2.7.0
	 *
	 * @param string $url URI resource.
	 * @param str|array $args Optional. Override the defaults.
	 * @return array containing 'headers', 'body', 'response', 'cookies'
	 */
	function request( $url, $args = array() ) {
		global $wp_version;

		$defaults = array(
			'method' => 'GET',
			'timeout' => apply_filters( 'http_request_timeout', 5),
			'redirection' => apply_filters( 'http_request_redirection_count', 5),
			'httpversion' => apply_filters( 'http_request_version', '1.0'),
			'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )  ),
			'blocking' => true,
			'headers' => array(),
			'cookies' => array(),
			'body' => null,
			'compress' => false,
			'decompress' => true,
			'sslverify' => true
		);

		$r = wp_parse_args( $args, $defaults );
		$r = apply_filters( 'http_request_args', $r, $url );

		$arrURL = parse_url($url);

		if ( $this->block_request( $url ) )
			return new WP_Error('http_request_failed', 'User has blocked requests through HTTP.');

		// Determine if this is a https call and pass that on to the transport functions
		// so that we can blacklist the transports that do not support ssl verification
		$r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl';

		// Determine if this request is to OUR install of WordPress
		$homeURL = parse_url(get_bloginfo('url'));
		$r['local'] = $homeURL['host'] == $arrURL['host'] || 'localhost' == $arrURL['host'];
		unset($homeURL);

		if ( is_null( $r['headers'] ) )
			$r['headers'] = array();

		if ( ! is_array($r['headers']) ) {
			$processedHeaders = WP_Http::processHeaders($r['headers']);
			$r['headers'] = $processedHeaders['headers'];
		}

		if ( isset($r['headers']['User-Agent']) ) {
			$r['user-agent'] = $r['headers']['User-Agent'];
			unset($r['headers']['User-Agent']);
		}

		if ( isset($r['headers']['user-agent']) ) {
			$r['user-agent'] = $r['headers']['user-agent'];
			unset($r['headers']['user-agent']);
		}

		// Construct Cookie: header if any cookies are set
		WP_Http::buildCookieHeader( $r );

		if ( WP_Http_Encoding::is_available() )
			$r['headers']['Accept-Encoding'] = WP_Http_Encoding::accept_encoding();

		if ( is_null($r['body']) ) {
			// Some servers fail when sending content without the content-length
			// header being set.
			$r['headers']['Content-Length'] = 0;
			$transports = WP_Http::_getTransport($r);
		} else {
			if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) {
				if ( ! version_compare(phpversion(), '5.1.2', '>=') )
					$r['body'] = _http_build_query($r['body'], null, '&');
				else
					$r['body'] = http_build_query($r['body'], null, '&');
				$r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset');
				$r['headers']['Content-Length'] = strlen($r['body']);
			}

			if ( ! isset( $r['headers']['Content-Length'] ) && ! isset( $r['headers']['content-length'] ) )
				$r['headers']['Content-Length'] = strlen($r['body']);

			$transports = WP_Http::_postTransport($r);
		}

		if ( has_action('http_api_debug') )
			do_action('http_api_debug', $transports, 'transports_list');

		$response = array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() );
		foreach ( (array) $transports as $transport ) {
			$response = $transport->request($url, $r);

			if ( has_action('http_api_debug') )
				do_action( 'http_api_debug', $response, 'response', get_class($transport) );

			if ( ! is_wp_error($response) )
				return $response;
		}

		return $response;
	}
예제 #7
0
 /**
  * What encoding types to accept and their priority values.
  *
  * @since 2.8
  *
  * @return string Types of encoding to accept.
  */
 public static function accept_encoding($url, $args)
 {
     $type = array();
     $compression_enabled = WP_Http_Encoding::is_available();
     if (!$args['decompress']) {
         // decompression specifically disabled
         $compression_enabled = false;
     } elseif ($args['stream']) {
         // disable when streaming to file
         $compression_enabled = false;
     } elseif (isset($args['limit-response-size'])) {
         // If only partial content is being requested, we won't be able to decompress it
         $compression_enabled = false;
     }
     if ($compression_enabled) {
         if (function_exists('gzinflate')) {
             $type[] = 'deflate;q=1.0';
         }
         if (function_exists('gzuncompress')) {
             $type[] = 'compress;q=0.5';
         }
         if (function_exists('gzdecode')) {
             $type[] = 'gzip;q=0.5';
         }
     }
     $type = apply_filters('wp_http_accept_encoding', $type, $url, $args);
     return implode(', ', $type);
 }