WP_HTTP_Proxy

Core class used to implement HTTP API proxy support.

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_Proxy { 
  2.  
  3. /** 
  4. * Whether proxy connection should be used. 
  5. * @since 2.8 
  6. * @use WP_PROXY_HOST 
  7. * @use WP_PROXY_PORT 
  8. * @return bool 
  9. */ 
  10. function is_enabled() { 
  11. return defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT'); 
  12.  
  13. /** 
  14. * Whether authentication should be used. 
  15. * @since 2.8 
  16. * @use WP_PROXY_USERNAME 
  17. * @use WP_PROXY_PASSWORD 
  18. * @return bool 
  19. */ 
  20. function use_authentication() { 
  21. return defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD'); 
  22.  
  23. /** 
  24. * Retrieve the host for the proxy server. 
  25. * @since 2.8 
  26. * @return string 
  27. */ 
  28. function host() { 
  29. if ( defined('WP_PROXY_HOST') ) 
  30. return WP_PROXY_HOST; 
  31.  
  32. return ''; 
  33.  
  34. /** 
  35. * Retrieve the port for the proxy server. 
  36. * @since 2.8 
  37. * @return string 
  38. */ 
  39. function port() { 
  40. if ( defined('WP_PROXY_PORT') ) 
  41. return WP_PROXY_PORT; 
  42.  
  43. return ''; 
  44.  
  45. /** 
  46. * Retrieve the username for proxy authentication. 
  47. * @since 2.8 
  48. * @return string 
  49. */ 
  50. function username() { 
  51. if ( defined('WP_PROXY_USERNAME') ) 
  52. return WP_PROXY_USERNAME; 
  53.  
  54. return ''; 
  55.  
  56. /** 
  57. * Retrieve the password for proxy authentication. 
  58. * @since 2.8 
  59. * @return string 
  60. */ 
  61. function password() { 
  62. if ( defined('WP_PROXY_PASSWORD') ) 
  63. return WP_PROXY_PASSWORD; 
  64.  
  65. return ''; 
  66.  
  67. /** 
  68. * Retrieve authentication string for proxy authentication. 
  69. * @since 2.8 
  70. * @return string 
  71. */ 
  72. function authentication() { 
  73. return $this->username() . ':' . $this->password(); 
  74.  
  75. /** 
  76. * Retrieve header string for proxy authentication. 
  77. * @since 2.8 
  78. * @return string 
  79. */ 
  80. function authentication_header() { 
  81. return 'Proxy-Authentication: Basic ' . base64_encode( $this->authentication() ); 
  82.  
  83. /** 
  84. * Whether URL should be sent through the proxy server. 
  85. * We want to keep localhost and the blog URL from being sent through the proxy server, because 
  86. * some proxies can not handle this. We also have the constant available for defining other 
  87. * hosts that won't be sent through the proxy. 
  88. * @uses WP_PROXY_BYPASS_HOSTS 
  89. * @since unknown 
  90. * @param string $uri URI to check. 
  91. * @return bool True, to send through the proxy and false if, the proxy should not be used. 
  92. */ 
  93. function send_through_proxy( $uri ) { 
  94. // parse_url() only handles http, https type URLs, and will emit E_WARNING on failure. 
  95. // This will be displayed on blogs, which is not reasonable. 
  96. $check = @parse_url($uri); 
  97.  
  98. // Malformed URL, can not process, but this could mean ssl, so let through anyway. 
  99. if ( $check === false ) 
  100. return true; 
  101.  
  102. $home = parse_url( backpress_get_option( 'application_uri' ) ); 
  103.  
  104. if ( $check['host'] == 'localhost' || $check['host'] == $home['host'] ) 
  105. return false; 
  106.  
  107. if ( !defined('WP_PROXY_BYPASS_HOSTS') ) 
  108. return true; 
  109.  
  110. static $bypass_hosts; 
  111. if ( null == $bypass_hosts ) 
  112. $bypass_hosts = preg_split('|, \s*|', WP_PROXY_BYPASS_HOSTS); 
  113.  
  114. return !in_array( $check['host'], $bypass_hosts );