WordPressを読む 67-5 /blog/wp-includes/class-http.php 5
2015/04/09
目次
- 1 /blog/wp-includes/class-http.php5
- 2 WP_HTTP_Proxy::is_enabled()
- 3 WP_HTTP_Proxy::use_authentication()
- 4 WP_HTTP_Proxy::host()
- 5 WP_HTTP_Proxy::port()
- 6 WP_HTTP_Proxy::username()
- 7 WP_HTTP_Proxy::password()
- 8 WP_HTTP_Proxy::authentication()
- 9 WP_HTTP_Proxy::authentication_header()
- 10 WP_HTTP_Proxy::send_through_proxy()
- 11 WP_Http_Cookie::
- 12 WP_Http_Cookie::__construct()
- 13 WP_Http_Cookie::test()
- 14 WP_Http_Cookie::getHeaderValue()
- 15 WP_Http_Cookie::getFullHeader()
/blog/wp-includes/class-http.php5
WP_HTTP_Proxy::is_enabled()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | /** * Adds Proxy support to the WordPress HTTP API. * * There are caveats to proxy support. It requires that defines be made in the wp-config.php file to * enable proxy support. There are also a few filters that plugins can hook into for some of the * constants. * * Please note that only BASIC authentication is supported by most transports. * cURL MAY support more methods (such as NTLM authentication) depending on your environment. * * The constants are as follows: * <ol> * <li>WP_PROXY_HOST - Enable proxy support and host for connecting.</li> * <li>WP_PROXY_PORT - Proxy port for connection. No default, must be defined.</li> * <li>WP_PROXY_USERNAME - Proxy username, if it requires authentication.</li> * <li>WP_PROXY_PASSWORD - Proxy password, if it requires authentication.</li> * <li>WP_PROXY_BYPASS_HOSTS - Will prevent the hosts in this list from going through the proxy. * You do not need to have localhost and the blog host in this list, because they will not be passed * through the proxy. The list should be presented in a comma separated list, wildcards using * are supported, eg. *.wordpress.org</li> * </ol> * * An example can be as seen below. * <code> * define('WP_PROXY_HOST', '192.168.84.101'); * define('WP_PROXY_PORT', '8080'); * define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com, *.wordpress.org'); * * * @link http://core.trac.wordpress.org/ticket/4011 Proxy support ticket in WordPress. * @link http://core.trac.wordpress.org/ticket/14636 Allow wildcard domains in WP_PROXY_BYPASS_HOSTS * @since 2.8.0 */ class WP_HTTP_Proxy { /** * Whether proxy connection should be used. * * @since 2.8.0 * * @use WP_PROXY_HOST * @use WP_PROXY_PORT * * @return bool */ public function is_enabled() { return defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT'); } |
WP_HTTP_Proxy::use_authentication()
1 2 3 4 5 6 7 8 9 10 11 12 13 | /** * Whether authentication should be used. * * @since 2.8.0 * * @use WP_PROXY_USERNAME * @use WP_PROXY_PASSWORD * * @return bool */ public function use_authentication() { return defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD'); } |
WP_HTTP_Proxy::host()
1 2 3 4 5 6 7 8 9 10 11 12 13 | /** * Retrieve the host for the proxy server. * * @since 2.8.0 * * @return string */ public function host() { if ( defined('WP_PROXY_HOST') ) return WP_PROXY_HOST; return ''; } |
WP_HTTP_Proxy::port()
1 2 3 4 5 6 7 8 9 10 11 12 13 | /** * Retrieve the port for the proxy server. * * @since 2.8.0 * * @return string */ public function port() { if ( defined('WP_PROXY_PORT') ) return WP_PROXY_PORT; return ''; } |
WP_HTTP_Proxy::username()
1 2 3 4 5 6 7 8 9 10 11 12 13 | /** * Retrieve the username for proxy authentication. * * @since 2.8.0 * * @return string */ public function username() { if ( defined('WP_PROXY_USERNAME') ) return WP_PROXY_USERNAME; return ''; } |
WP_HTTP_Proxy::password()
1 2 3 4 5 6 7 8 9 10 11 12 13 | /** * Retrieve the password for proxy authentication. * * @since 2.8.0 * * @return string */ public function password() { if ( defined('WP_PROXY_PASSWORD') ) return WP_PROXY_PASSWORD; return ''; } |
WP_HTTP_Proxy::authentication()
1 2 3 4 5 6 7 8 9 10 | /** * Retrieve authentication string for proxy authentication. * * @since 2.8.0 * * @return string */ public function authentication() { return $this->username() . ':' . $this->password(); } |
WP_HTTP_Proxy::authentication_header()
1 2 3 4 5 6 7 8 9 10 | /** * Retrieve header string for proxy authentication. * * @since 2.8.0 * * @return string */ public function authentication_header() { return 'Proxy-Authorization: Basic ' . base64_encode( $this->authentication() ); } |
WP_HTTP_Proxy::send_through_proxy()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | /** * Whether URL should be sent through the proxy server. * * We want to keep localhost and the blog URL from being sent through the proxy server, because * some proxies can not handle this. We also have the constant available for defining other * hosts that won't be sent through the proxy. * * @uses WP_PROXY_BYPASS_HOSTS * @since 2.8.0 * * @param string $uri URI to check. * @return bool True, to send through the proxy and false if, the proxy should not be used. */ public function send_through_proxy( $uri ) { /* * parse_url() only handles http, https type URLs, and will emit E_WARNING on failure. * This will be displayed on blogs, which is not reasonable. */ $check = @parse_url($uri); // Malformed URL, can not process, but this could mean ssl, so let through anyway. if ( $check === false ) return true; $home = parse_url( get_option('siteurl') ); /** * Filter whether to preempt sending the request through the proxy server. * * Returning false will bypass the proxy; returning true will send * the request through the proxy. Returning null bypasses the filter. * * @since 3.5.0 * * @param null $override Whether to override the request result. Default null. * @param string $uri URL to check. * @param array $check Associative array result of parsing the URI. * @param array $home Associative array result of parsing the site URL. */ $result = apply_filters( 'pre_http_send_through_proxy', null, $uri, $check, $home ); if ( ! is_null( $result ) ) return $result; if ( 'localhost' == $check['host'] || ( isset( $home['host'] ) && $home['host'] == $check['host'] ) ) return false; if ( !defined('WP_PROXY_BYPASS_HOSTS') ) return true; static $bypass_hosts; static $wildcard_regex = false; if ( null == $bypass_hosts ) { $bypass_hosts = preg_split('|,\s*|', WP_PROXY_BYPASS_HOSTS); if ( false !== strpos(WP_PROXY_BYPASS_HOSTS, '*') ) { $wildcard_regex = array(); foreach ( $bypass_hosts as $host ) $wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) ); $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i'; } } if ( !empty($wildcard_regex) ) return !preg_match($wildcard_regex, $check['host']); else return !in_array( $check['host'], $bypass_hosts ); } } |
WP_HTTP_Proxy::クラス定義終了
WP_Http_Cookie::
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | /** * Internal representation of a single cookie. * * Returned cookies are represented using this class, and when cookies are set, if they are not * already a WP_Http_Cookie() object, then they are turned into one. * * @todo The WordPress convention is to use underscores instead of camelCase for function and method * names. Need to switch to use underscores instead for the methods. * * @package WordPress * @subpackage HTTP * @since 2.8.0 */ class WP_Http_Cookie { /** * Cookie name. * * @since 2.8.0 * @var string */ public $name; /** * Cookie value. * * @since 2.8.0 * @var string */ public $value; /** * When the cookie expires. * * @since 2.8.0 * @var string */ public $expires; /** * Cookie URL path. * * @since 2.8.0 * @var string */ public $path; /** * Cookie Domain. * * @since 2.8.0 * @var string */ public $domain; |
WP_Http_Cookie::__construct()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | /** * Sets up this cookie object. * * The parameter $data should be either an associative array containing the indices names below * or a header string detailing it. * * @since 2.8.0 * @access public * * @param string|array $data { * Raw cookie data as header string or data array. * * @type string $name Cookie name. * @type mixed $value Value. Should NOT already be urlencoded. * @type string|int $expires Optional. Unix timestamp or formatted date. Default null. * @type string $path Optional. Path. Default '/'. * @type string $domain Optional. Domain. Default host of parsed $requested_url. * @type int $port Optional. Port. Default null. * } * @param string $requested_url The URL which the cookie was set on, used for default $domain * and $port values. */ public function __construct( $data, $requested_url = '' ) { if ( $requested_url ) $arrURL = @parse_url( $requested_url ); if ( isset( $arrURL['host'] ) ) $this->domain = $arrURL['host']; $this->path = isset( $arrURL['path'] ) ? $arrURL['path'] : '/'; if ( '/' != substr( $this->path, -1 ) ) $this->path = dirname( $this->path ) . '/'; if ( is_string( $data ) ) { // Assume it's a header string direct from a previous request. $pairs = explode( ';', $data ); // Special handling for first pair; name=value. Also be careful of "=" in value. $name = trim( substr( $pairs[0], 0, strpos( $pairs[0], '=' ) ) ); $value = substr( $pairs[0], strpos( $pairs[0], '=' ) + 1 ); $this->name = $name; $this->value = urldecode( $value ); // Removes name=value from items. array_shift( $pairs ); // Set everything else as a property. foreach ( $pairs as $pair ) { $pair = rtrim($pair); // Handle the cookie ending in ; which results in a empty final pair. if ( empty($pair) ) continue; list( $key, $val ) = strpos( $pair, '=' ) ? explode( '=', $pair ) : array( $pair, '' ); $key = strtolower( trim( $key ) ); if ( 'expires' == $key ) $val = strtotime( $val ); $this->$key = $val; } } else { if ( !isset( $data['name'] ) ) return false; // Set properties based directly on parameters. foreach ( array( 'name', 'value', 'path', 'domain', 'port' ) as $field ) { if ( isset( $data[ $field ] ) ) $this->$field = $data[ $field ]; } if ( isset( $data['expires'] ) ) $this->expires = is_int( $data['expires'] ) ? $data['expires'] : strtotime( $data['expires'] ); else $this->expires = null; } } |
WP_Http_Cookie::test()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | /** * Confirms that it's OK to send this cookie to the URL checked against. * * Decision is based on RFC 2109/2965, so look there for details on validity. * * @access public * @since 2.8.0 * * @param string $url URL you intend to send this cookie to * @return boolean true if allowed, false otherwise. */ public function test( $url ) { if ( is_null( $this->name ) ) return false; // Expires - if expired then nothing else matters. if ( isset( $this->expires ) && time() > $this->expires ) return false; // Get details on the URL we're thinking about sending to. $url = parse_url( $url ); $url['port'] = isset( $url['port'] ) ? $url['port'] : ( 'https' == $url['scheme'] ? 443 : 80 ); $url['path'] = isset( $url['path'] ) ? $url['path'] : '/'; // Values to use for comparison against the URL. $path = isset( $this->path ) ? $this->path : '/'; $port = isset( $this->port ) ? $this->port : null; $domain = isset( $this->domain ) ? strtolower( $this->domain ) : strtolower( $url['host'] ); if ( false === stripos( $domain, '.' ) ) $domain .= '.local'; // Host - very basic check that the request URL ends with the domain restriction (minus leading dot). $domain = substr( $domain, 0, 1 ) == '.' ? substr( $domain, 1 ) : $domain; if ( substr( $url['host'], -strlen( $domain ) ) != $domain ) return false; // Port - supports "port-lists" in the format: "80,8000,8080". if ( !empty( $port ) && !in_array( $url['port'], explode( ',', $port) ) ) return false; // Path - request path must start with path restriction. if ( substr( $url['path'], 0, strlen( $path ) ) != $path ) return false; return true; } |
WP_Http_Cookie::getHeaderValue()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /** * Convert cookie name and value back to header string. * * @access public * @since 2.8.0 * * @return string Header encoded cookie name and value. */ public function getHeaderValue() { if ( ! isset( $this->name ) || ! isset( $this->value ) ) return ''; /** * Filter the header-encoded cookie value. * * @since 3.4.0 * * @param string $value The cookie value. * @param string $name The cookie name. */ return $this->name . '=' . apply_filters( 'wp_http_cookie_value', $this->value, $this->name ); } |
WP_Http_Cookie::getFullHeader()
1 2 3 4 5 6 7 8 9 10 11 12 | /** * Retrieve cookie header for usage in the rest of the WordPress HTTP API. * * @access public * @since 2.8.0 * * @return string */ public function getFullHeader() { return 'Cookie: ' . $this->getHeaderValue(); } } |