mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 01:27:36 +01:00
Coding Standards: Rename the $process
variable to $processed_response
for clarity in WP_Http_Streams::request()
.
Includes minor code layout fixes for better readability. Follow-up to [8516], [51826], [51929], [51931]. See #53359. Built from https://develop.svn.wordpress.org/trunk@51940 git-svn-id: http://core.svn.wordpress.org/trunk@51529 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
7a0a07d691
commit
156a453ed9
@ -92,6 +92,7 @@ class WP_Http_Streams {
|
|||||||
|
|
||||||
$is_local = isset( $parsed_args['local'] ) && $parsed_args['local'];
|
$is_local = isset( $parsed_args['local'] ) && $parsed_args['local'];
|
||||||
$ssl_verify = isset( $parsed_args['sslverify'] ) && $parsed_args['sslverify'];
|
$ssl_verify = isset( $parsed_args['sslverify'] ) && $parsed_args['sslverify'];
|
||||||
|
|
||||||
if ( $is_local ) {
|
if ( $is_local ) {
|
||||||
/**
|
/**
|
||||||
* Filters whether SSL should be verified for local HTTP API requests.
|
* Filters whether SSL should be verified for local HTTP API requests.
|
||||||
@ -141,10 +142,24 @@ class WP_Http_Streams {
|
|||||||
|
|
||||||
if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) {
|
if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) {
|
||||||
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
|
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
|
||||||
$handle = @stream_socket_client( 'tcp://' . $proxy->host() . ':' . $proxy->port(), $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context );
|
$handle = @stream_socket_client(
|
||||||
|
'tcp://' . $proxy->host() . ':' . $proxy->port(),
|
||||||
|
$connection_error,
|
||||||
|
$connection_error_str,
|
||||||
|
$connect_timeout,
|
||||||
|
STREAM_CLIENT_CONNECT,
|
||||||
|
$context
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
|
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
|
||||||
$handle = @stream_socket_client( $connect_host . ':' . $parsed_url['port'], $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context );
|
$handle = @stream_socket_client(
|
||||||
|
$connect_host . ':' . $parsed_url['port'],
|
||||||
|
$connection_error,
|
||||||
|
$connection_error_str,
|
||||||
|
$connect_timeout,
|
||||||
|
STREAM_CLIENT_CONNECT,
|
||||||
|
$context
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $secure_transport ) {
|
if ( $secure_transport ) {
|
||||||
@ -152,9 +167,23 @@ class WP_Http_Streams {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) {
|
if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) {
|
||||||
$handle = stream_socket_client( 'tcp://' . $proxy->host() . ':' . $proxy->port(), $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context );
|
$handle = stream_socket_client(
|
||||||
|
'tcp://' . $proxy->host() . ':' . $proxy->port(),
|
||||||
|
$connection_error,
|
||||||
|
$connection_error_str,
|
||||||
|
$connect_timeout,
|
||||||
|
STREAM_CLIENT_CONNECT,
|
||||||
|
$context
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$handle = stream_socket_client( $connect_host . ':' . $parsed_url['port'], $connection_error, $connection_error_str, $connect_timeout, STREAM_CLIENT_CONNECT, $context );
|
$handle = stream_socket_client(
|
||||||
|
$connect_host . ':' . $parsed_url['port'],
|
||||||
|
$connection_error,
|
||||||
|
$connection_error_str,
|
||||||
|
$connect_timeout,
|
||||||
|
STREAM_CLIENT_CONNECT,
|
||||||
|
$context
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,9 +214,9 @@ class WP_Http_Streams {
|
|||||||
$strHeaders = strtoupper( $parsed_args['method'] ) . ' ' . $requestPath . ' HTTP/' . $parsed_args['httpversion'] . "\r\n";
|
$strHeaders = strtoupper( $parsed_args['method'] ) . ' ' . $requestPath . ' HTTP/' . $parsed_args['httpversion'] . "\r\n";
|
||||||
|
|
||||||
$include_port_in_host_header = (
|
$include_port_in_host_header = (
|
||||||
( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) ||
|
( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) )
|
||||||
( 'http' === $parsed_url['scheme'] && 80 != $parsed_url['port'] ) ||
|
|| ( 'http' === $parsed_url['scheme'] && 80 != $parsed_url['port'] )
|
||||||
( 'https' === $parsed_url['scheme'] && 443 != $parsed_url['port'] )
|
|| ( 'https' === $parsed_url['scheme'] && 443 != $parsed_url['port'] )
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( $include_port_in_host_header ) {
|
if ( $include_port_in_host_header ) {
|
||||||
@ -238,6 +267,7 @@ class WP_Http_Streams {
|
|||||||
$bodyStarted = false;
|
$bodyStarted = false;
|
||||||
$keep_reading = true;
|
$keep_reading = true;
|
||||||
$block_size = 4096;
|
$block_size = 4096;
|
||||||
|
|
||||||
if ( isset( $parsed_args['limit_response_size'] ) ) {
|
if ( isset( $parsed_args['limit_response_size'] ) ) {
|
||||||
$block_size = min( $block_size, $parsed_args['limit_response_size'] );
|
$block_size = min( $block_size, $parsed_args['limit_response_size'] );
|
||||||
}
|
}
|
||||||
@ -249,6 +279,7 @@ class WP_Http_Streams {
|
|||||||
} else {
|
} else {
|
||||||
$stream_handle = fopen( $parsed_args['filename'], 'w+' );
|
$stream_handle = fopen( $parsed_args['filename'], 'w+' );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $stream_handle ) {
|
if ( ! $stream_handle ) {
|
||||||
return new WP_Error(
|
return new WP_Error(
|
||||||
'http_request_failed',
|
'http_request_failed',
|
||||||
@ -262,22 +293,25 @@ class WP_Http_Streams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$bytes_written = 0;
|
$bytes_written = 0;
|
||||||
|
|
||||||
while ( ! feof( $handle ) && $keep_reading ) {
|
while ( ! feof( $handle ) && $keep_reading ) {
|
||||||
$block = fread( $handle, $block_size );
|
$block = fread( $handle, $block_size );
|
||||||
if ( ! $bodyStarted ) {
|
if ( ! $bodyStarted ) {
|
||||||
$strResponse .= $block;
|
$strResponse .= $block;
|
||||||
if ( strpos( $strResponse, "\r\n\r\n" ) ) {
|
if ( strpos( $strResponse, "\r\n\r\n" ) ) {
|
||||||
$process = WP_Http::processResponse( $strResponse );
|
$processed_response = WP_Http::processResponse( $strResponse );
|
||||||
$bodyStarted = true;
|
$bodyStarted = true;
|
||||||
$block = $process['body'];
|
$block = $processed_response['body'];
|
||||||
unset( $strResponse );
|
unset( $strResponse );
|
||||||
$process['body'] = '';
|
$processed_response['body'] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this_block_size = strlen( $block );
|
$this_block_size = strlen( $block );
|
||||||
|
|
||||||
if ( isset( $parsed_args['limit_response_size'] ) && ( $bytes_written + $this_block_size ) > $parsed_args['limit_response_size'] ) {
|
if ( isset( $parsed_args['limit_response_size'] )
|
||||||
|
&& ( $bytes_written + $this_block_size ) > $parsed_args['limit_response_size']
|
||||||
|
) {
|
||||||
$this_block_size = ( $parsed_args['limit_response_size'] - $bytes_written );
|
$this_block_size = ( $parsed_args['limit_response_size'] - $bytes_written );
|
||||||
$block = substr( $block, 0, $this_block_size );
|
$block = substr( $block, 0, $this_block_size );
|
||||||
}
|
}
|
||||||
@ -292,31 +326,41 @@ class WP_Http_Streams {
|
|||||||
|
|
||||||
$bytes_written += $bytes_written_to_file;
|
$bytes_written += $bytes_written_to_file;
|
||||||
|
|
||||||
$keep_reading = ! isset( $parsed_args['limit_response_size'] ) || $bytes_written < $parsed_args['limit_response_size'];
|
$keep_reading = (
|
||||||
|
! isset( $parsed_args['limit_response_size'] )
|
||||||
|
|| $bytes_written < $parsed_args['limit_response_size']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose( $stream_handle );
|
fclose( $stream_handle );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$header_length = 0;
|
$header_length = 0;
|
||||||
|
|
||||||
while ( ! feof( $handle ) && $keep_reading ) {
|
while ( ! feof( $handle ) && $keep_reading ) {
|
||||||
$block = fread( $handle, $block_size );
|
$block = fread( $handle, $block_size );
|
||||||
$strResponse .= $block;
|
$strResponse .= $block;
|
||||||
|
|
||||||
if ( ! $bodyStarted && strpos( $strResponse, "\r\n\r\n" ) ) {
|
if ( ! $bodyStarted && strpos( $strResponse, "\r\n\r\n" ) ) {
|
||||||
$header_length = strpos( $strResponse, "\r\n\r\n" ) + 4;
|
$header_length = strpos( $strResponse, "\r\n\r\n" ) + 4;
|
||||||
$bodyStarted = true;
|
$bodyStarted = true;
|
||||||
}
|
}
|
||||||
$keep_reading = ( ! $bodyStarted || ! isset( $parsed_args['limit_response_size'] ) || strlen( $strResponse ) < ( $header_length + $parsed_args['limit_response_size'] ) );
|
|
||||||
|
$keep_reading = (
|
||||||
|
! $bodyStarted
|
||||||
|
|| ! isset( $parsed_args['limit_response_size'] )
|
||||||
|
|| strlen( $strResponse ) < ( $header_length + $parsed_args['limit_response_size'] )
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$process = WP_Http::processResponse( $strResponse );
|
$processed_response = WP_Http::processResponse( $strResponse );
|
||||||
unset( $strResponse );
|
unset( $strResponse );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose( $handle );
|
fclose( $handle );
|
||||||
|
|
||||||
$processed_headers = WP_Http::processHeaders( $process['headers'], $url );
|
$processed_headers = WP_Http::processHeaders( $processed_response['headers'], $url );
|
||||||
|
|
||||||
$response = array(
|
$response = array(
|
||||||
'headers' => $processed_headers['headers'],
|
'headers' => $processed_headers['headers'],
|
||||||
@ -334,21 +378,26 @@ class WP_Http_Streams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the body was chunk encoded, then decode it.
|
// If the body was chunk encoded, then decode it.
|
||||||
if ( ! empty( $process['body'] ) && isset( $processed_headers['headers']['transfer-encoding'] )
|
if ( ! empty( $processed_response['body'] )
|
||||||
|
&& isset( $processed_headers['headers']['transfer-encoding'] )
|
||||||
&& 'chunked' === $processed_headers['headers']['transfer-encoding']
|
&& 'chunked' === $processed_headers['headers']['transfer-encoding']
|
||||||
) {
|
) {
|
||||||
$process['body'] = WP_Http::chunkTransferDecode( $process['body'] );
|
$processed_response['body'] = WP_Http::chunkTransferDecode( $processed_response['body'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( true === $parsed_args['decompress'] && true === WP_Http_Encoding::should_decode( $processed_headers['headers'] ) ) {
|
if ( true === $parsed_args['decompress']
|
||||||
$process['body'] = WP_Http_Encoding::decompress( $process['body'] );
|
&& true === WP_Http_Encoding::should_decode( $processed_headers['headers'] )
|
||||||
|
) {
|
||||||
|
$processed_response['body'] = WP_Http_Encoding::decompress( $processed_response['body'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset( $parsed_args['limit_response_size'] ) && strlen( $process['body'] ) > $parsed_args['limit_response_size'] ) {
|
if ( isset( $parsed_args['limit_response_size'] )
|
||||||
$process['body'] = substr( $process['body'], 0, $parsed_args['limit_response_size'] );
|
&& strlen( $processed_response['body'] ) > $parsed_args['limit_response_size']
|
||||||
|
) {
|
||||||
|
$processed_response['body'] = substr( $processed_response['body'], 0, $parsed_args['limit_response_size'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
$response['body'] = $process['body'];
|
$response['body'] = $processed_response['body'];
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.9-alpha-51939';
|
$wp_version = '5.9-alpha-51940';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user