Changeset 50842 for trunk/src/wp-includes/Requests/Transport/fsockopen.php
- Timestamp:
- 05/11/2021 07:40:41 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/Requests/Transport/fsockopen.php
r46586 r50842 63 63 throw new Requests_Exception('Invalid URL.', 'invalidurl', $url); 64 64 } 65 $host = $url_parts['host'];66 $context = stream_context_create();67 $verifyname = false;65 $host = $url_parts['host']; 66 $context = stream_context_create(); 67 $verifyname = false; 68 68 $case_insensitive_headers = new Requests_Utility_CaseInsensitiveDictionary($headers); 69 69 … … 76 76 77 77 $context_options = array( 78 'verify_peer' => true, 79 // 'CN_match' => $host, 80 'capture_peer_cert' => true 78 'verify_peer' => true, 79 'capture_peer_cert' => true, 81 80 ); 82 $verifyname = true;81 $verifyname = true; 83 82 84 83 // SNI, if enabled (OpenSSL >=0.9.8j) 84 // phpcs:ignore PHPCompatibility.Constants.NewConstants.openssl_tlsext_server_nameFound 85 85 if (defined('OPENSSL_TLSEXT_SERVER_NAME') && OPENSSL_TLSEXT_SERVER_NAME) { 86 86 $context_options['SNI_enabled'] = true; … … 92 92 if (isset($options['verify'])) { 93 93 if ($options['verify'] === false) { 94 $context_options['verify_peer'] = false; 94 $context_options['verify_peer'] = false; 95 $context_options['verify_peer_name'] = false; 96 $verifyname = false; 95 97 } 96 98 elseif (is_string($options['verify'])) { … … 101 103 if (isset($options['verifyname']) && $options['verifyname'] === false) { 102 104 $context_options['verify_peer_name'] = false; 103 $verifyname = false;105 $verifyname = false; 104 106 } 105 107 … … 117 119 $remote_socket .= ':' . $url_parts['port']; 118 120 121 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler 119 122 set_error_handler(array($this, 'connect_error_handler'), E_WARNING | E_NOTICE); 120 123 … … 151 154 152 155 $request_body = ''; 153 $out = sprintf("%s %s HTTP/%.1F\r\n", $options['type'], $path, $options['protocol_version']);156 $out = sprintf("%s %s HTTP/%.1F\r\n", $options['type'], $path, $options['protocol_version']); 154 157 155 158 if ($options['type'] !== Requests::TRACE) { 156 159 if (is_array($data)) { 157 $request_body = http_build_query($data, null, '&');160 $request_body = http_build_query($data, '', '&'); 158 161 } 159 162 else { … … 161 164 } 162 165 163 if (!empty($data)) { 166 // Always include Content-length on POST requests to prevent 167 // 411 errors from some servers when the body is empty. 168 if (!empty($data) || $options['type'] === Requests::POST) { 164 169 if (!isset($case_insensitive_headers['Content-Length'])) { 165 170 $headers['Content-Length'] = strlen($request_body); … … 175 180 $out .= sprintf('Host: %s', $url_parts['host']); 176 181 177 if (( 'http' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 80 ) || ( 'https' === strtolower($url_parts['scheme']) && $url_parts['port'] !== 443)) {182 if ((strtolower($url_parts['scheme']) === 'http' && $url_parts['port'] !== 80) || (strtolower($url_parts['scheme']) === 'https' && $url_parts['port'] !== 443)) { 178 183 $out .= ':' . $url_parts['port']; 179 184 } … … 221 226 222 227 $timeout_sec = (int) floor($options['timeout']); 223 if ($timeout_sec == $options['timeout']) {228 if ($timeout_sec === $options['timeout']) { 224 229 $timeout_msec = 0; 225 230 } … … 229 234 stream_set_timeout($socket, $timeout_sec, $timeout_msec); 230 235 231 $response = $body = $headers = ''; 236 $response = ''; 237 $body = ''; 238 $headers = ''; 232 239 $this->info = stream_get_meta_data($socket); 233 $size = 0;234 $doingbody = false;235 $download = false;240 $size = 0; 241 $doingbody = false; 242 $download = false; 236 243 if ($options['filename']) { 237 244 $download = fopen($options['filename'], 'wb'); … … 249 256 if (strpos($response, "\r\n\r\n")) { 250 257 list($headers, $block) = explode("\r\n\r\n", $response, 2); 251 $doingbody = true;258 $doingbody = true; 252 259 } 253 260 } … … 265 272 // Limit the length 266 273 $limited_length = ($this->max_bytes - $size); 267 $block = substr($block, 0, $limited_length);274 $block = substr($block, 0, $limited_length); 268 275 } 269 276 } … … 301 308 public function request_multiple($requests, $options) { 302 309 $responses = array(); 303 $class = get_class($this);310 $class = get_class($this); 304 311 foreach ($requests as $id => $request) { 305 312 try { 306 $handler = new $class();313 $handler = new $class(); 307 314 $responses[$id] = $handler->request($request['url'], $request['headers'], $request['data'], $request['options']); 308 315 … … 354 361 } 355 362 356 $url_parts['query'] .= '&' . http_build_query($data, null, '&');357 $url_parts['query'] = trim($url_parts['query'], '&');363 $url_parts['query'] .= '&' . http_build_query($data, '', '&'); 364 $url_parts['query'] = trim($url_parts['query'], '&'); 358 365 } 359 366 if (isset($url_parts['path'])) {
Note: See TracChangeset
for help on using the changeset viewer.