wp/wp-includes/class-wp-http-proxy.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 19 3d72ae0968f4
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
   150 	public function authentication_header() {
   150 	public function authentication_header() {
   151 		return 'Proxy-Authorization: Basic ' . base64_encode( $this->authentication() );
   151 		return 'Proxy-Authorization: Basic ' . base64_encode( $this->authentication() );
   152 	}
   152 	}
   153 
   153 
   154 	/**
   154 	/**
   155 	 * Whether URL should be sent through the proxy server.
   155 	 * Determines whether the request should be sent through a proxy.
   156 	 *
   156 	 *
   157 	 * We want to keep localhost and the site URL from being sent through the proxy server, because
   157 	 * We want to keep localhost and the site URL from being sent through the proxy, because
   158 	 * some proxies can not handle this. We also have the constant available for defining other
   158 	 * some proxies can not handle this. We also have the constant available for defining other
   159 	 * hosts that won't be sent through the proxy.
   159 	 * hosts that won't be sent through the proxy.
   160 	 *
   160 	 *
   161 	 * @since 2.8.0
   161 	 * @since 2.8.0
   162 	 *
   162 	 *
   163 	 * @staticvar array|null $bypass_hosts
   163 	 * @param string $uri URL of the request.
   164 	 * @staticvar array      $wildcard_regex
   164 	 * @return bool Whether to send the request through the proxy.
   165 	 *
       
   166 	 * @param string $uri URI to check.
       
   167 	 * @return bool True, to send through the proxy and false if, the proxy should not be used.
       
   168 	 */
   165 	 */
   169 	public function send_through_proxy( $uri ) {
   166 	public function send_through_proxy( $uri ) {
   170 		/*
   167 		$check = parse_url( $uri );
   171 		 * parse_url() only handles http, https type URLs, and will emit E_WARNING on failure.
       
   172 		 * This will be displayed on sites, which is not reasonable.
       
   173 		 */
       
   174 		$check = @parse_url( $uri );
       
   175 
   168 
   176 		// Malformed URL, can not process, but this could mean ssl, so let through anyway.
   169 		// Malformed URL, can not process, but this could mean ssl, so let through anyway.
   177 		if ( $check === false ) {
   170 		if ( false === $check ) {
   178 			return true;
   171 			return true;
   179 		}
   172 		}
   180 
   173 
   181 		$home = parse_url( get_option( 'siteurl' ) );
   174 		$home = parse_url( get_option( 'siteurl' ) );
   182 
   175 
   183 		/**
   176 		/**
   184 		 * Filters whether to preempt sending the request through the proxy server.
   177 		 * Filters whether to preempt sending the request through the proxy.
   185 		 *
   178 		 *
   186 		 * Returning false will bypass the proxy; returning true will send
   179 		 * Returning false will bypass the proxy; returning true will send
   187 		 * the request through the proxy. Returning null bypasses the filter.
   180 		 * the request through the proxy. Returning null bypasses the filter.
   188 		 *
   181 		 *
   189 		 * @since 3.5.0
   182 		 * @since 3.5.0
   190 		 *
   183 		 *
   191 		 * @param null   $override Whether to override the request result. Default null.
   184 		 * @param bool|null $override Whether to send the request through the proxy. Default null.
   192 		 * @param string $uri      URL to check.
   185 		 * @param string    $uri      URL of the request.
   193 		 * @param array  $check    Associative array result of parsing the URI.
   186 		 * @param array     $check    Associative array result of parsing the request URL with `parse_url()`.
   194 		 * @param array  $home     Associative array result of parsing the site URL.
   187 		 * @param array     $home     Associative array result of parsing the site URL with `parse_url()`.
   195 		 */
   188 		 */
   196 		$result = apply_filters( 'pre_http_send_through_proxy', null, $uri, $check, $home );
   189 		$result = apply_filters( 'pre_http_send_through_proxy', null, $uri, $check, $home );
   197 		if ( ! is_null( $result ) ) {
   190 		if ( ! is_null( $result ) ) {
   198 			return $result;
   191 			return $result;
   199 		}
   192 		}
   200 
   193 
   201 		if ( 'localhost' == $check['host'] || ( isset( $home['host'] ) && $home['host'] == $check['host'] ) ) {
   194 		if ( 'localhost' === $check['host'] || ( isset( $home['host'] ) && $home['host'] === $check['host'] ) ) {
   202 			return false;
   195 			return false;
   203 		}
   196 		}
   204 
   197 
   205 		if ( ! defined( 'WP_PROXY_BYPASS_HOSTS' ) ) {
   198 		if ( ! defined( 'WP_PROXY_BYPASS_HOSTS' ) ) {
   206 			return true;
   199 			return true;
   221 		}
   214 		}
   222 
   215 
   223 		if ( ! empty( $wildcard_regex ) ) {
   216 		if ( ! empty( $wildcard_regex ) ) {
   224 			return ! preg_match( $wildcard_regex, $check['host'] );
   217 			return ! preg_match( $wildcard_regex, $check['host'] );
   225 		} else {
   218 		} else {
   226 			return ! in_array( $check['host'], $bypass_hosts );
   219 			return ! in_array( $check['host'], $bypass_hosts, true );
   227 		}
   220 		}
   228 	}
   221 	}
   229 }
   222 }