- Timestamp:
- 10/27/2021 03:02:04 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-http-streams.php
r51929 r51940 93 93 $is_local = isset( $parsed_args['local'] ) && $parsed_args['local']; 94 94 $ssl_verify = isset( $parsed_args['sslverify'] ) && $parsed_args['sslverify']; 95 95 96 if ( $is_local ) { 96 97 /** … … 142 143 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { 143 144 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged 144 $handle = @stream_socket_client( 'tcp://' . $proxy->host() . ':' . $proxy->port(), $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context ); 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 ); 145 153 } else { 146 154 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged 147 $handle = @stream_socket_client( $connect_host . ':' . $parsed_url['port'], $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context ); 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 ); 148 163 } 149 164 … … 153 168 } else { 154 169 if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) { 155 $handle = stream_socket_client( 'tcp://' . $proxy->host() . ':' . $proxy->port(), $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context ); 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 ); 156 178 } else { 157 $handle = stream_socket_client( $connect_host . ':' . $parsed_url['port'], $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context ); 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 ); 158 187 } 159 188 } … … 186 215 187 216 $include_port_in_host_header = ( 188 ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) ||189 ( 'http' === $parsed_url['scheme'] && 80 != $parsed_url['port'] ) ||190 ( 'https' === $parsed_url['scheme'] && 443 != $parsed_url['port'] )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'] ) 191 220 ); 192 221 … … 239 268 $keep_reading = true; 240 269 $block_size = 4096; 270 241 271 if ( isset( $parsed_args['limit_response_size'] ) ) { 242 272 $block_size = min( $block_size, $parsed_args['limit_response_size'] ); … … 250 280 $stream_handle = fopen( $parsed_args['filename'], 'w+' ); 251 281 } 282 252 283 if ( ! $stream_handle ) { 253 284 return new WP_Error( … … 263 294 264 295 $bytes_written = 0; 296 265 297 while ( ! feof( $handle ) && $keep_reading ) { 266 298 $block = fread( $handle, $block_size ); … … 268 300 $strResponse .= $block; 269 301 if ( strpos( $strResponse, "\r\n\r\n" ) ) { 270 $process 271 $bodyStarted = true;272 $block = $process['body'];302 $processed_response = WP_Http::processResponse( $strResponse ); 303 $bodyStarted = true; 304 $block = $processed_response['body']; 273 305 unset( $strResponse ); 274 $process ['body'] = '';306 $processed_response['body'] = ''; 275 307 } 276 308 } … … 278 310 $this_block_size = strlen( $block ); 279 311 280 if ( isset( $parsed_args['limit_response_size'] ) && ( $bytes_written + $this_block_size ) > $parsed_args['limit_response_size'] ) { 312 if ( isset( $parsed_args['limit_response_size'] ) 313 && ( $bytes_written + $this_block_size ) > $parsed_args['limit_response_size'] 314 ) { 281 315 $this_block_size = ( $parsed_args['limit_response_size'] - $bytes_written ); 282 316 $block = substr( $block, 0, $this_block_size ); … … 293 327 $bytes_written += $bytes_written_to_file; 294 328 295 $keep_reading = ! isset( $parsed_args['limit_response_size'] ) || $bytes_written < $parsed_args['limit_response_size']; 329 $keep_reading = ( 330 ! isset( $parsed_args['limit_response_size'] ) 331 || $bytes_written < $parsed_args['limit_response_size'] 332 ); 296 333 } 297 334 … … 300 337 } else { 301 338 $header_length = 0; 339 302 340 while ( ! feof( $handle ) && $keep_reading ) { 303 341 $block = fread( $handle, $block_size ); 304 342 $strResponse .= $block; 343 305 344 if ( ! $bodyStarted && strpos( $strResponse, "\r\n\r\n" ) ) { 306 345 $header_length = strpos( $strResponse, "\r\n\r\n" ) + 4; 307 346 $bodyStarted = true; 308 347 } 309 $keep_reading = ( ! $bodyStarted || ! isset( $parsed_args['limit_response_size'] ) || strlen( $strResponse ) < ( $header_length + $parsed_args['limit_response_size'] ) ); 310 } 311 312 $process = WP_Http::processResponse( $strResponse ); 348 349 $keep_reading = ( 350 ! $bodyStarted 351 || ! isset( $parsed_args['limit_response_size'] ) 352 || strlen( $strResponse ) < ( $header_length + $parsed_args['limit_response_size'] ) 353 ); 354 } 355 356 $processed_response = WP_Http::processResponse( $strResponse ); 313 357 unset( $strResponse ); 314 358 … … 317 361 fclose( $handle ); 318 362 319 $processed_headers = WP_Http::processHeaders( $process ['headers'], $url );363 $processed_headers = WP_Http::processHeaders( $processed_response['headers'], $url ); 320 364 321 365 $response = array( … … 335 379 336 380 // If the body was chunk encoded, then decode it. 337 if ( ! empty( $process['body'] ) && isset( $processed_headers['headers']['transfer-encoding'] ) 381 if ( ! empty( $processed_response['body'] ) 382 && isset( $processed_headers['headers']['transfer-encoding'] ) 338 383 && 'chunked' === $processed_headers['headers']['transfer-encoding'] 339 384 ) { 340 $process['body'] = WP_Http::chunkTransferDecode( $process['body'] ); 341 } 342 343 if ( true === $parsed_args['decompress'] && true === WP_Http_Encoding::should_decode( $processed_headers['headers'] ) ) { 344 $process['body'] = WP_Http_Encoding::decompress( $process['body'] ); 345 } 346 347 if ( isset( $parsed_args['limit_response_size'] ) && strlen( $process['body'] ) > $parsed_args['limit_response_size'] ) { 348 $process['body'] = substr( $process['body'], 0, $parsed_args['limit_response_size'] ); 349 } 350 351 $response['body'] = $process['body']; 385 $processed_response['body'] = WP_Http::chunkTransferDecode( $processed_response['body'] ); 386 } 387 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'] ); 392 } 393 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'] ); 398 } 399 400 $response['body'] = $processed_response['body']; 352 401 353 402 return $response;
Note: See TracChangeset
for help on using the changeset viewer.