author | ymh <ymh.work@gmail.com> |
Tue, 27 Sep 2022 16:37:53 +0200 | |
changeset 19 | 3d72ae0968f4 |
parent 18 | be944660c56a |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
* HTTP API: WP_Http_Streams class |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
* @package WordPress |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
* @subpackage HTTP |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
* Core class used to integrate PHP Streams as an HTTP transport. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
* @since 3.7.0 Combined with the fsockopen transport and switched to `stream_socket_client()`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
16 |
class WP_Http_Streams { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
17 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
* Send a HTTP request to a URI using PHP Streams. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
* @see WP_Http::request For default options descriptions. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
* @since 3.7.0 Combined with the fsockopen transport and switched to stream_socket_client(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
* |
16 | 25 |
* @param string $url The request URL. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
26 |
* @param string|array $args Optional. Override the defaults. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
* @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
28 |
*/ |
9 | 29 |
public function request( $url, $args = array() ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
30 |
$defaults = array( |
9 | 31 |
'method' => 'GET', |
32 |
'timeout' => 5, |
|
33 |
'redirection' => 5, |
|
34 |
'httpversion' => '1.0', |
|
35 |
'blocking' => true, |
|
36 |
'headers' => array(), |
|
37 |
'body' => null, |
|
38 |
'cookies' => array(), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
39 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
40 |
|
16 | 41 |
$parsed_args = wp_parse_args( $args, $defaults ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
|
16 | 43 |
if ( isset( $parsed_args['headers']['User-Agent'] ) ) { |
44 |
$parsed_args['user-agent'] = $parsed_args['headers']['User-Agent']; |
|
45 |
unset( $parsed_args['headers']['User-Agent'] ); |
|
46 |
} elseif ( isset( $parsed_args['headers']['user-agent'] ) ) { |
|
47 |
$parsed_args['user-agent'] = $parsed_args['headers']['user-agent']; |
|
48 |
unset( $parsed_args['headers']['user-agent'] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
49 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
50 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
51 |
// Construct Cookie: header if any cookies are set. |
16 | 52 |
WP_Http::buildCookieHeader( $parsed_args ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
53 |
|
19 | 54 |
$parsed_url = parse_url( $url ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
55 |
|
19 | 56 |
$connect_host = $parsed_url['host']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
57 |
|
19 | 58 |
$secure_transport = ( 'ssl' === $parsed_url['scheme'] || 'https' === $parsed_url['scheme'] ); |
59 |
if ( ! isset( $parsed_url['port'] ) ) { |
|
60 |
if ( 'ssl' === $parsed_url['scheme'] || 'https' === $parsed_url['scheme'] ) { |
|
61 |
$parsed_url['port'] = 443; |
|
62 |
$secure_transport = true; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
63 |
} else { |
19 | 64 |
$parsed_url['port'] = 80; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
65 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
66 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
67 |
|
16 | 68 |
// Always pass a path, defaulting to the root in cases such as http://example.com. |
19 | 69 |
if ( ! isset( $parsed_url['path'] ) ) { |
70 |
$parsed_url['path'] = '/'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
71 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
72 |
|
16 | 73 |
if ( isset( $parsed_args['headers']['Host'] ) || isset( $parsed_args['headers']['host'] ) ) { |
74 |
if ( isset( $parsed_args['headers']['Host'] ) ) { |
|
19 | 75 |
$parsed_url['host'] = $parsed_args['headers']['Host']; |
9 | 76 |
} else { |
19 | 77 |
$parsed_url['host'] = $parsed_args['headers']['host']; |
9 | 78 |
} |
16 | 79 |
unset( $parsed_args['headers']['Host'], $parsed_args['headers']['host'] ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
80 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
81 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
82 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
83 |
* Certain versions of PHP have issues with 'localhost' and IPv6, It attempts to connect |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
84 |
* to ::1, which fails when the server is not set up for it. For compatibility, always |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
85 |
* connect to the IPv4 address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
86 |
*/ |
16 | 87 |
if ( 'localhost' === strtolower( $connect_host ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
88 |
$connect_host = '127.0.0.1'; |
9 | 89 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
90 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
91 |
$connect_host = $secure_transport ? 'ssl://' . $connect_host : 'tcp://' . $connect_host; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
92 |
|
16 | 93 |
$is_local = isset( $parsed_args['local'] ) && $parsed_args['local']; |
94 |
$ssl_verify = isset( $parsed_args['sslverify'] ) && $parsed_args['sslverify']; |
|
19 | 95 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
96 |
if ( $is_local ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
97 |
/** |
18 | 98 |
* Filters whether SSL should be verified for local HTTP API requests. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
99 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
100 |
* @since 2.8.0 |
9 | 101 |
* @since 5.1.0 The `$url` parameter was added. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
102 |
* |
9 | 103 |
* @param bool $ssl_verify Whether to verify the SSL connection. Default true. |
104 |
* @param string $url The request URL. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
105 |
*/ |
9 | 106 |
$ssl_verify = apply_filters( 'https_local_ssl_verify', $ssl_verify, $url ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
107 |
} elseif ( ! $is_local ) { |
19 | 108 |
/** This filter is documented in wp-includes/class-wp-http.php */ |
9 | 109 |
$ssl_verify = apply_filters( 'https_ssl_verify', $ssl_verify, $url ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
110 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
111 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
112 |
$proxy = new WP_HTTP_Proxy(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
113 |
|
9 | 114 |
$context = stream_context_create( |
115 |
array( |
|
116 |
'ssl' => array( |
|
117 |
'verify_peer' => $ssl_verify, |
|
19 | 118 |
// 'CN_match' => $parsed_url['host'], // This is handled by self::verify_ssl_certificate(). |
9 | 119 |
'capture_peer_cert' => $ssl_verify, |
120 |
'SNI_enabled' => true, |
|
16 | 121 |
'cafile' => $parsed_args['sslcertificates'], |
9 | 122 |
'allow_self_signed' => ! $ssl_verify, |
123 |
), |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
124 |
) |
9 | 125 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
126 |
|
16 | 127 |
$timeout = (int) floor( $parsed_args['timeout'] ); |
128 |
$utimeout = $timeout == $parsed_args['timeout'] ? 0 : 1000000 * $parsed_args['timeout'] % 1000000; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
129 |
$connect_timeout = max( $timeout, 1 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
130 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
131 |
// Store error number. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
132 |
$connection_error = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
133 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
134 |
// Store error string. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
135 |
$connection_error_str = null; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
136 |
|
9 | 137 |
if ( ! WP_DEBUG ) { |
16 | 138 |
// In the event that the SSL connection fails, silence the many PHP warnings. |
9 | 139 |
if ( $secure_transport ) { |
140 |
$error_reporting = error_reporting( 0 ); |
|
141 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
142 |
|
9 | 143 |
if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { |
16 | 144 |
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
19 | 145 |
$handle = @stream_socket_client( |
146 |
'tcp://' . $proxy->host() . ':' . $proxy->port(), |
|
147 |
$connection_error, |
|
148 |
$connection_error_str, |
|
149 |
$connect_timeout, |
|
150 |
STREAM_CLIENT_CONNECT, |
|
151 |
$context |
|
152 |
); |
|
9 | 153 |
} else { |
16 | 154 |
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged |
19 | 155 |
$handle = @stream_socket_client( |
156 |
$connect_host . ':' . $parsed_url['port'], |
|
157 |
$connection_error, |
|
158 |
$connection_error_str, |
|
159 |
$connect_timeout, |
|
160 |
STREAM_CLIENT_CONNECT, |
|
161 |
$context |
|
162 |
); |
|
9 | 163 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
164 |
|
9 | 165 |
if ( $secure_transport ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
166 |
error_reporting( $error_reporting ); |
9 | 167 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
168 |
} else { |
9 | 169 |
if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { |
19 | 170 |
$handle = stream_socket_client( |
171 |
'tcp://' . $proxy->host() . ':' . $proxy->port(), |
|
172 |
$connection_error, |
|
173 |
$connection_error_str, |
|
174 |
$connect_timeout, |
|
175 |
STREAM_CLIENT_CONNECT, |
|
176 |
$context |
|
177 |
); |
|
9 | 178 |
} else { |
19 | 179 |
$handle = stream_socket_client( |
180 |
$connect_host . ':' . $parsed_url['port'], |
|
181 |
$connection_error, |
|
182 |
$connection_error_str, |
|
183 |
$connect_timeout, |
|
184 |
STREAM_CLIENT_CONNECT, |
|
185 |
$context |
|
186 |
); |
|
9 | 187 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
188 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
189 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
190 |
if ( false === $handle ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
191 |
// SSL connection failed due to expired/invalid cert, or, OpenSSL configuration is broken. |
9 | 192 |
if ( $secure_transport && 0 === $connection_error && '' === $connection_error_str ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
193 |
return new WP_Error( 'http_request_failed', __( 'The SSL certificate for the host could not be verified.' ) ); |
9 | 194 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
195 |
|
9 | 196 |
return new WP_Error( 'http_request_failed', $connection_error . ': ' . $connection_error_str ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
197 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
198 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
199 |
// Verify that the SSL certificate is valid for this request. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
200 |
if ( $secure_transport && $ssl_verify && ! $proxy->is_enabled() ) { |
19 | 201 |
if ( ! self::verify_ssl_certificate( $handle, $parsed_url['host'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
202 |
return new WP_Error( 'http_request_failed', __( 'The SSL certificate for the host could not be verified.' ) ); |
9 | 203 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
204 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
205 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
206 |
stream_set_timeout( $handle, $timeout, $utimeout ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
207 |
|
16 | 208 |
if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { // Some proxies require full URL in this field. |
19 | 209 |
$request_path = $url; |
9 | 210 |
} else { |
19 | 211 |
$request_path = $parsed_url['path'] . ( isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '' ); |
9 | 212 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
213 |
|
19 | 214 |
$headers = strtoupper( $parsed_args['method'] ) . ' ' . $request_path . ' HTTP/' . $parsed_args['httpversion'] . "\r\n"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
215 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
216 |
$include_port_in_host_header = ( |
19 | 217 |
( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) |
218 |
|| ( 'http' === $parsed_url['scheme'] && 80 != $parsed_url['port'] ) |
|
219 |
|| ( 'https' === $parsed_url['scheme'] && 443 != $parsed_url['port'] ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
220 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
221 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
222 |
if ( $include_port_in_host_header ) { |
19 | 223 |
$headers .= 'Host: ' . $parsed_url['host'] . ':' . $parsed_url['port'] . "\r\n"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
224 |
} else { |
19 | 225 |
$headers .= 'Host: ' . $parsed_url['host'] . "\r\n"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
226 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
227 |
|
16 | 228 |
if ( isset( $parsed_args['user-agent'] ) ) { |
19 | 229 |
$headers .= 'User-agent: ' . $parsed_args['user-agent'] . "\r\n"; |
9 | 230 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
231 |
|
16 | 232 |
if ( is_array( $parsed_args['headers'] ) ) { |
19 | 233 |
foreach ( (array) $parsed_args['headers'] as $header => $header_value ) { |
234 |
$headers .= $header . ': ' . $header_value . "\r\n"; |
|
9 | 235 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
236 |
} else { |
19 | 237 |
$headers .= $parsed_args['headers']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
238 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
239 |
|
9 | 240 |
if ( $proxy->use_authentication() ) { |
19 | 241 |
$headers .= $proxy->authentication_header() . "\r\n"; |
9 | 242 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
243 |
|
19 | 244 |
$headers .= "\r\n"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
245 |
|
16 | 246 |
if ( ! is_null( $parsed_args['body'] ) ) { |
19 | 247 |
$headers .= $parsed_args['body']; |
9 | 248 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
249 |
|
19 | 250 |
fwrite( $handle, $headers ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
251 |
|
16 | 252 |
if ( ! $parsed_args['blocking'] ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
253 |
stream_set_blocking( $handle, 0 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
254 |
fclose( $handle ); |
9 | 255 |
return array( |
256 |
'headers' => array(), |
|
257 |
'body' => '', |
|
258 |
'response' => array( |
|
259 |
'code' => false, |
|
260 |
'message' => false, |
|
261 |
), |
|
262 |
'cookies' => array(), |
|
263 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
264 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
265 |
|
19 | 266 |
$response = ''; |
267 |
$body_started = false; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
268 |
$keep_reading = true; |
9 | 269 |
$block_size = 4096; |
19 | 270 |
|
16 | 271 |
if ( isset( $parsed_args['limit_response_size'] ) ) { |
272 |
$block_size = min( $block_size, $parsed_args['limit_response_size'] ); |
|
9 | 273 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
274 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
275 |
// If streaming to a file setup the file handle. |
16 | 276 |
if ( $parsed_args['stream'] ) { |
9 | 277 |
if ( ! WP_DEBUG ) { |
16 | 278 |
$stream_handle = @fopen( $parsed_args['filename'], 'w+' ); |
9 | 279 |
} else { |
16 | 280 |
$stream_handle = fopen( $parsed_args['filename'], 'w+' ); |
9 | 281 |
} |
19 | 282 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
283 |
if ( ! $stream_handle ) { |
9 | 284 |
return new WP_Error( |
285 |
'http_request_failed', |
|
286 |
sprintf( |
|
16 | 287 |
/* translators: 1: fopen(), 2: File name. */ |
9 | 288 |
__( 'Could not open handle for %1$s to %2$s.' ), |
289 |
'fopen()', |
|
16 | 290 |
$parsed_args['filename'] |
9 | 291 |
) |
292 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
293 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
294 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
295 |
$bytes_written = 0; |
19 | 296 |
|
9 | 297 |
while ( ! feof( $handle ) && $keep_reading ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
298 |
$block = fread( $handle, $block_size ); |
19 | 299 |
if ( ! $body_started ) { |
300 |
$response .= $block; |
|
301 |
if ( strpos( $response, "\r\n\r\n" ) ) { |
|
302 |
$processed_response = WP_Http::processResponse( $response ); |
|
303 |
$body_started = true; |
|
304 |
$block = $processed_response['body']; |
|
305 |
unset( $response ); |
|
306 |
$processed_response['body'] = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
307 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
308 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
309 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
310 |
$this_block_size = strlen( $block ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
311 |
|
19 | 312 |
if ( isset( $parsed_args['limit_response_size'] ) |
313 |
&& ( $bytes_written + $this_block_size ) > $parsed_args['limit_response_size'] |
|
314 |
) { |
|
16 | 315 |
$this_block_size = ( $parsed_args['limit_response_size'] - $bytes_written ); |
9 | 316 |
$block = substr( $block, 0, $this_block_size ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
317 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
318 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
319 |
$bytes_written_to_file = fwrite( $stream_handle, $block ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
320 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
321 |
if ( $bytes_written_to_file != $this_block_size ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
322 |
fclose( $handle ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
323 |
fclose( $stream_handle ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
324 |
return new WP_Error( 'http_request_failed', __( 'Failed to write request to temporary file.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
325 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
326 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
327 |
$bytes_written += $bytes_written_to_file; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
328 |
|
19 | 329 |
$keep_reading = ( |
330 |
! isset( $parsed_args['limit_response_size'] ) |
|
331 |
|| $bytes_written < $parsed_args['limit_response_size'] |
|
332 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
333 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
334 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
335 |
fclose( $stream_handle ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
336 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
337 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
338 |
$header_length = 0; |
19 | 339 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
340 |
while ( ! feof( $handle ) && $keep_reading ) { |
19 | 341 |
$block = fread( $handle, $block_size ); |
342 |
$response .= $block; |
|
343 |
||
344 |
if ( ! $body_started && strpos( $response, "\r\n\r\n" ) ) { |
|
345 |
$header_length = strpos( $response, "\r\n\r\n" ) + 4; |
|
346 |
$body_started = true; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
347 |
} |
19 | 348 |
|
349 |
$keep_reading = ( |
|
350 |
! $body_started |
|
351 |
|| ! isset( $parsed_args['limit_response_size'] ) |
|
352 |
|| strlen( $response ) < ( $header_length + $parsed_args['limit_response_size'] ) |
|
353 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
354 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
355 |
|
19 | 356 |
$processed_response = WP_Http::processResponse( $response ); |
357 |
unset( $response ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
358 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
359 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
360 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
361 |
fclose( $handle ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
362 |
|
19 | 363 |
$processed_headers = WP_Http::processHeaders( $processed_response['headers'], $url ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
364 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
365 |
$response = array( |
19 | 366 |
'headers' => $processed_headers['headers'], |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
367 |
// Not yet processed. |
9 | 368 |
'body' => null, |
19 | 369 |
'response' => $processed_headers['response'], |
370 |
'cookies' => $processed_headers['cookies'], |
|
16 | 371 |
'filename' => $parsed_args['filename'], |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
372 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
373 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
374 |
// Handle redirects. |
16 | 375 |
$redirect_response = WP_Http::handle_redirects( $url, $parsed_args, $response ); |
376 |
if ( false !== $redirect_response ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
377 |
return $redirect_response; |
9 | 378 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
379 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
380 |
// If the body was chunk encoded, then decode it. |
19 | 381 |
if ( ! empty( $processed_response['body'] ) |
382 |
&& isset( $processed_headers['headers']['transfer-encoding'] ) |
|
383 |
&& 'chunked' === $processed_headers['headers']['transfer-encoding'] |
|
16 | 384 |
) { |
19 | 385 |
$processed_response['body'] = WP_Http::chunkTransferDecode( $processed_response['body'] ); |
9 | 386 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
387 |
|
19 | 388 |
if ( true === $parsed_args['decompress'] |
389 |
&& true === WP_Http_Encoding::should_decode( $processed_headers['headers'] ) |
|
390 |
) { |
|
391 |
$processed_response['body'] = WP_Http_Encoding::decompress( $processed_response['body'] ); |
|
9 | 392 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
393 |
|
19 | 394 |
if ( isset( $parsed_args['limit_response_size'] ) |
395 |
&& strlen( $processed_response['body'] ) > $parsed_args['limit_response_size'] |
|
396 |
) { |
|
397 |
$processed_response['body'] = substr( $processed_response['body'], 0, $parsed_args['limit_response_size'] ); |
|
9 | 398 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
399 |
|
19 | 400 |
$response['body'] = $processed_response['body']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
401 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
402 |
return $response; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
403 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
404 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
405 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
406 |
* Verifies the received SSL certificate against its Common Names and subjectAltName fields. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
407 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
408 |
* PHP's SSL verifications only verify that it's a valid Certificate, it doesn't verify if |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
409 |
* the certificate is valid for the hostname which was requested. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
410 |
* This function verifies the requested hostname against certificate's subjectAltName field, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
411 |
* if that is empty, or contains no DNS entries, a fallback to the Common Name field is used. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
412 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
413 |
* IP Address support is included if the request is being made to an IP address. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
414 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
415 |
* @since 3.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
416 |
* |
19 | 417 |
* @param resource $stream The PHP Stream which the SSL request is being made over |
418 |
* @param string $host The hostname being requested |
|
419 |
* @return bool If the certificate presented in $stream is valid for $host |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
420 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
421 |
public static function verify_ssl_certificate( $stream, $host ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
422 |
$context_options = stream_context_get_options( $stream ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
423 |
|
9 | 424 |
if ( empty( $context_options['ssl']['peer_certificate'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
425 |
return false; |
9 | 426 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
427 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
428 |
$cert = openssl_x509_parse( $context_options['ssl']['peer_certificate'] ); |
9 | 429 |
if ( ! $cert ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
430 |
return false; |
9 | 431 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
432 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
433 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
434 |
* If the request is being made to an IP address, we'll validate against IP fields |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
435 |
* in the cert (if they exist) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
436 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
437 |
$host_type = ( WP_Http::is_ip_address( $host ) ? 'ip' : 'dns' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
438 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
439 |
$certificate_hostnames = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
440 |
if ( ! empty( $cert['extensions']['subjectAltName'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
441 |
$match_against = preg_split( '/,\s*/', $cert['extensions']['subjectAltName'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
442 |
foreach ( $match_against as $match ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
443 |
list( $match_type, $match_host ) = explode( ':', $match ); |
16 | 444 |
if ( strtolower( trim( $match_type ) ) === $host_type ) { // IP: or DNS: |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
445 |
$certificate_hostnames[] = strtolower( trim( $match_host ) ); |
9 | 446 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
447 |
} |
9 | 448 |
} elseif ( ! empty( $cert['subject']['CN'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
449 |
// Only use the CN when the certificate includes no subjectAltName extension. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
450 |
$certificate_hostnames[] = strtolower( $cert['subject']['CN'] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
451 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
452 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
453 |
// Exact hostname/IP matches. |
16 | 454 |
if ( in_array( strtolower( $host ), $certificate_hostnames, true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
455 |
return true; |
9 | 456 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
457 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
458 |
// IP's can't be wildcards, Stop processing. |
16 | 459 |
if ( 'ip' === $host_type ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
460 |
return false; |
9 | 461 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
462 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
463 |
// Test to see if the domain is at least 2 deep for wildcard support. |
9 | 464 |
if ( substr_count( $host, '.' ) < 2 ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
465 |
return false; |
9 | 466 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
467 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
468 |
// Wildcard subdomains certs (*.example.com) are valid for a.example.com but not a.b.example.com. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
469 |
$wildcard_host = preg_replace( '/^[^.]+\./', '*.', $host ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
470 |
|
16 | 471 |
return in_array( strtolower( $wildcard_host ), $certificate_hostnames, true ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
472 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
473 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
474 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
475 |
* Determines whether this class can be used for retrieving a URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
476 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
477 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
478 |
* @since 3.7.0 Combined with the fsockopen transport and switched to stream_socket_client(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
479 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
480 |
* @param array $args Optional. Array of request arguments. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
481 |
* @return bool False means this class can not be used, true means it can. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
482 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
483 |
public static function test( $args = array() ) { |
9 | 484 |
if ( ! function_exists( 'stream_socket_client' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
485 |
return false; |
9 | 486 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
487 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
488 |
$is_ssl = isset( $args['ssl'] ) && $args['ssl']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
489 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
490 |
if ( $is_ssl ) { |
9 | 491 |
if ( ! extension_loaded( 'openssl' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
492 |
return false; |
9 | 493 |
} |
494 |
if ( ! function_exists( 'openssl_x509_parse' ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
495 |
return false; |
9 | 496 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
497 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
498 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
499 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
500 |
* Filters whether streams can be used as a transport for retrieving a URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
501 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
502 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
503 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
504 |
* @param bool $use_class Whether the class can be used. Default true. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
505 |
* @param array $args Request arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
506 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
507 |
return apply_filters( 'use_streams_transport', true, $args ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
508 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
509 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
510 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
511 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
512 |
* Deprecated HTTP Transport method which used fsockopen. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
513 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
514 |
* This class is not used, and is included for backward compatibility only. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
515 |
* All code should make use of WP_Http directly through its API. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
516 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
517 |
* @see WP_HTTP::request |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
518 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
519 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
520 |
* @deprecated 3.7.0 Please use WP_HTTP::request() directly |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
521 |
*/ |
19 | 522 |
class WP_HTTP_Fsockopen extends WP_Http_Streams { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
523 |
// For backward compatibility for users who are using the class directly. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
524 |
} |