WP_Http_ExtHTTP

HTTP request method uses HTTP extension to retrieve the url.

Defined (1)

The class is defined in the following location(s).

/bp-forums/bbpress/bb-includes/backpress/class.wp-http.php  
  1. class WP_Http_ExtHTTP { 
  2. /** 
  3. * Send a HTTP request to a URI using HTTP extension. 
  4. * Does not support non-blocking. 
  5. * @access public 
  6. * @since 2.7 
  7. * @param string $url 
  8. * @param str|array $args Optional. Override the defaults. 
  9. * @return array 'headers', 'body', 'cookies' and 'response' keys. 
  10. */ 
  11. function request($url, $args = array()) { 
  12. $defaults = array( 
  13. 'method' => 'GET', 'timeout' => 5,  
  14. 'redirection' => 5, 'httpversion' => '1.0',  
  15. 'blocking' => true,  
  16. 'headers' => array(), 'body' => null, 'cookies' => array() 
  17. ); 
  18.  
  19. $r = wp_parse_args( $args, $defaults ); 
  20.  
  21. if ( isset($r['headers']['User-Agent']) ) { 
  22. $r['user-agent'] = $r['headers']['User-Agent']; 
  23. unset($r['headers']['User-Agent']); 
  24. } else if( isset($r['headers']['user-agent']) ) { 
  25. $r['user-agent'] = $r['headers']['user-agent']; 
  26. unset($r['headers']['user-agent']); 
  27.  
  28. // Construct Cookie: header if any cookies are set 
  29. WP_Http::buildCookieHeader( $r ); 
  30.  
  31. switch ( $r['method'] ) { 
  32. case 'POST': 
  33. $r['method'] = HTTP_METH_POST; 
  34. break; 
  35. case 'HEAD': 
  36. $r['method'] = HTTP_METH_HEAD; 
  37. break; 
  38. case 'GET': 
  39. default: 
  40. $r['method'] = HTTP_METH_GET; 
  41.  
  42. $arrURL = parse_url($url); 
  43.  
  44. if ( 'http' != $arrURL['scheme'] || 'https' != $arrURL['scheme'] ) 
  45. $url = preg_replace('|^' . preg_quote($arrURL['scheme'], '|') . '|', 'http', $url); 
  46.  
  47. $is_local = isset($args['local']) && $args['local']; 
  48. $ssl_verify = isset($args['sslverify']) && $args['sslverify']; 
  49. if ( $is_local ) 
  50. $ssl_verify = apply_filters('https_local_ssl_verify', $ssl_verify); 
  51. elseif ( ! $is_local ) 
  52. $ssl_verify = apply_filters('https_ssl_verify', $ssl_verify); 
  53.  
  54. $options = array( 
  55. 'timeout' => $r['timeout'],  
  56. 'connecttimeout' => $r['timeout'],  
  57. 'redirect' => $r['redirection'],  
  58. 'useragent' => $r['user-agent'],  
  59. 'headers' => $r['headers'],  
  60. 'ssl' => array( 
  61. 'verifypeer' => $ssl_verify,  
  62. 'verifyhost' => $ssl_verify 
  63. ); 
  64.  
  65. // The HTTP extensions offers really easy proxy support. 
  66. $proxy = new WP_HTTP_Proxy(); 
  67.  
  68. if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { 
  69. $options['proxyhost'] = $proxy->host(); 
  70. $options['proxyport'] = $proxy->port(); 
  71. $options['proxytype'] = HTTP_PROXY_HTTP; 
  72.  
  73. if ( $proxy->use_authentication() ) { 
  74. $options['proxyauth'] = $proxy->authentication(); 
  75. $options['proxyauthtype'] = HTTP_AUTH_BASIC; 
  76.  
  77. if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) ) //Emits warning level notices for max redirects and timeouts 
  78. $strResponse = @http_request($r['method'], $url, $r['body'], $options, $info); 
  79. else 
  80. $strResponse = http_request($r['method'], $url, $r['body'], $options, $info); //Emits warning level notices for max redirects and timeouts 
  81.  
  82. // Error may still be set, Response may return headers or partial document, and error 
  83. // contains a reason the request was aborted, eg, timeout expired or max-redirects reached. 
  84. if ( false === $strResponse || ! empty($info['error']) ) 
  85. return new WP_Error('http_request_failed', $info['response_code'] . ': ' . $info['error']); 
  86.  
  87. if ( ! $r['blocking'] ) 
  88. return array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() ); 
  89.  
  90. list($theHeaders, $theBody) = explode("\r\n\r\n", $strResponse, 2); 
  91. $theHeaders = WP_Http::processHeaders($theHeaders); 
  92.  
  93. if ( ! empty( $theBody ) && isset( $theHeaders['headers']['transfer-encoding'] ) && 'chunked' == $theHeaders['headers']['transfer-encoding'] ) { 
  94. if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) ) 
  95. $theBody = @http_chunked_decode($theBody); 
  96. else 
  97. $theBody = http_chunked_decode($theBody); 
  98.  
  99. if ( true === $r['decompress'] && true === WP_Http_Encoding::should_decode($theHeaders['headers']) ) 
  100. $theBody = http_inflate( $theBody ); 
  101.  
  102. $theResponse = array(); 
  103. $theResponse['code'] = $info['response_code']; 
  104. $theResponse['message'] = get_status_header_desc($info['response_code']); 
  105.  
  106. return array('headers' => $theHeaders['headers'], 'body' => $theBody, 'response' => $theResponse, 'cookies' => $theHeaders['cookies']); 
  107.  
  108. /** 
  109. * Whether this class can be used for retrieving an URL. 
  110. * @static 
  111. * @since 2.7.0 
  112. * @return boolean False means this class can not be used, true means it can. 
  113. */ 
  114. function test($args = array()) { 
  115. return apply_filters('use_http_extension_transport', function_exists('http_request'), $args );