Changeset 45667 for trunk/src/wp-includes/class-wp-http-curl.php
- Timestamp:
- 07/25/2019 12:47:53 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-http-curl.php
r45590 r45667 80 80 ); 81 81 82 $ r= wp_parse_args( $args, $defaults );83 84 if ( isset( $ r['headers']['User-Agent'] ) ) {85 $ r['user-agent'] = $r['headers']['User-Agent'];86 unset( $ r['headers']['User-Agent'] );87 } elseif ( isset( $ r['headers']['user-agent'] ) ) {88 $ r['user-agent'] = $r['headers']['user-agent'];89 unset( $ r['headers']['user-agent'] );82 $parsed_args = wp_parse_args( $args, $defaults ); 83 84 if ( isset( $parsed_args['headers']['User-Agent'] ) ) { 85 $parsed_args['user-agent'] = $parsed_args['headers']['User-Agent']; 86 unset( $parsed_args['headers']['User-Agent'] ); 87 } elseif ( isset( $parsed_args['headers']['user-agent'] ) ) { 88 $parsed_args['user-agent'] = $parsed_args['headers']['user-agent']; 89 unset( $parsed_args['headers']['user-agent'] ); 90 90 } 91 91 92 92 // Construct Cookie: header if any cookies are set. 93 WP_Http::buildCookieHeader( $ r);93 WP_Http::buildCookieHeader( $parsed_args ); 94 94 95 95 $handle = curl_init(); … … 110 110 } 111 111 112 $is_local = isset( $ r['local'] ) && $r['local'];113 $ssl_verify = isset( $ r['sslverify'] ) && $r['sslverify'];112 $is_local = isset( $parsed_args['local'] ) && $parsed_args['local']; 113 $ssl_verify = isset( $parsed_args['sslverify'] ) && $parsed_args['sslverify']; 114 114 if ( $is_local ) { 115 115 /** This filter is documented in wp-includes/class-wp-http-streams.php */ … … 124 124 * a value of 0 will allow an unlimited timeout. 125 125 */ 126 $timeout = (int) ceil( $ r['timeout'] );126 $timeout = (int) ceil( $parsed_args['timeout'] ); 127 127 curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, $timeout ); 128 128 curl_setopt( $handle, CURLOPT_TIMEOUT, $timeout ); … … 134 134 135 135 if ( $ssl_verify ) { 136 curl_setopt( $handle, CURLOPT_CAINFO, $ r['sslcertificates'] );137 } 138 139 curl_setopt( $handle, CURLOPT_USERAGENT, $ r['user-agent'] );136 curl_setopt( $handle, CURLOPT_CAINFO, $parsed_args['sslcertificates'] ); 137 } 138 139 curl_setopt( $handle, CURLOPT_USERAGENT, $parsed_args['user-agent'] ); 140 140 141 141 /* … … 148 148 } 149 149 150 switch ( $ r['method'] ) {150 switch ( $parsed_args['method'] ) { 151 151 case 'HEAD': 152 152 curl_setopt( $handle, CURLOPT_NOBODY, true ); … … 154 154 case 'POST': 155 155 curl_setopt( $handle, CURLOPT_POST, true ); 156 curl_setopt( $handle, CURLOPT_POSTFIELDS, $ r['body'] );156 curl_setopt( $handle, CURLOPT_POSTFIELDS, $parsed_args['body'] ); 157 157 break; 158 158 case 'PUT': 159 159 curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, 'PUT' ); 160 curl_setopt( $handle, CURLOPT_POSTFIELDS, $ r['body'] );160 curl_setopt( $handle, CURLOPT_POSTFIELDS, $parsed_args['body'] ); 161 161 break; 162 162 default: 163 curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, $ r['method'] );164 if ( ! is_null( $ r['body'] ) ) {165 curl_setopt( $handle, CURLOPT_POSTFIELDS, $ r['body'] );163 curl_setopt( $handle, CURLOPT_CUSTOMREQUEST, $parsed_args['method'] ); 164 if ( ! is_null( $parsed_args['body'] ) ) { 165 curl_setopt( $handle, CURLOPT_POSTFIELDS, $parsed_args['body'] ); 166 166 } 167 167 break; 168 168 } 169 169 170 if ( true === $ r['blocking'] ) {170 if ( true === $parsed_args['blocking'] ) { 171 171 curl_setopt( $handle, CURLOPT_HEADERFUNCTION, array( $this, 'stream_headers' ) ); 172 172 curl_setopt( $handle, CURLOPT_WRITEFUNCTION, array( $this, 'stream_body' ) ); … … 175 175 curl_setopt( $handle, CURLOPT_HEADER, false ); 176 176 177 if ( isset( $ r['limit_response_size'] ) ) {178 $this->max_body_length = intval( $ r['limit_response_size'] );177 if ( isset( $parsed_args['limit_response_size'] ) ) { 178 $this->max_body_length = intval( $parsed_args['limit_response_size'] ); 179 179 } else { 180 180 $this->max_body_length = false; … … 182 182 183 183 // If streaming to a file open a file handle, and setup our curl streaming handler. 184 if ( $ r['stream'] ) {184 if ( $parsed_args['stream'] ) { 185 185 if ( ! WP_DEBUG ) { 186 $this->stream_handle = @fopen( $ r['filename'], 'w+' );186 $this->stream_handle = @fopen( $parsed_args['filename'], 'w+' ); 187 187 } else { 188 $this->stream_handle = fopen( $ r['filename'], 'w+' );188 $this->stream_handle = fopen( $parsed_args['filename'], 'w+' ); 189 189 } 190 190 if ( ! $this->stream_handle ) { … … 195 195 __( 'Could not open handle for %1$s to %2$s.' ), 196 196 'fopen()', 197 $ r['filename']197 $parsed_args['filename'] 198 198 ) 199 199 ); … … 203 203 } 204 204 205 if ( ! empty( $ r['headers'] ) ) {205 if ( ! empty( $parsed_args['headers'] ) ) { 206 206 // cURL expects full header strings in each element. 207 207 $headers = array(); 208 foreach ( $ r['headers'] as $name => $value ) {208 foreach ( $parsed_args['headers'] as $name => $value ) { 209 209 $headers[] = "{$name}: $value"; 210 210 } … … 212 212 } 213 213 214 if ( $ r['httpversion'] == '1.0' ) {214 if ( $parsed_args['httpversion'] == '1.0' ) { 215 215 curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 ); 216 216 } else { … … 227 227 * 228 228 * @param resource $handle The cURL handle returned by curl_init() (passed by reference). 229 * @param array $ rThe HTTP request arguments.229 * @param array $parsed_args The HTTP request arguments. 230 230 * @param string $url The request URL. 231 231 */ 232 do_action_ref_array( 'http_api_curl', array( &$handle, $ r, $url ) );232 do_action_ref_array( 'http_api_curl', array( &$handle, $parsed_args, $url ) ); 233 233 234 234 // We don't need to return the body, so don't. Just execute request and return. 235 if ( ! $ r['blocking'] ) {235 if ( ! $parsed_args['blocking'] ) { 236 236 curl_exec( $handle ); 237 237 … … 273 273 if ( CURLE_WRITE_ERROR /* 23 */ == $curl_error ) { 274 274 if ( ! $this->max_body_length || $this->max_body_length != $bytes_written_total ) { 275 if ( $ r['stream'] ) {275 if ( $parsed_args['stream'] ) { 276 276 curl_close( $handle ); 277 277 fclose( $this->stream_handle ); … … 297 297 curl_close( $handle ); 298 298 299 if ( $ r['stream'] ) {299 if ( $parsed_args['stream'] ) { 300 300 fclose( $this->stream_handle ); 301 301 } … … 306 306 'response' => $theHeaders['response'], 307 307 'cookies' => $theHeaders['cookies'], 308 'filename' => $ r['filename'],308 'filename' => $parsed_args['filename'], 309 309 ); 310 310 311 311 // Handle redirects. 312 $redirect_response = WP_HTTP::handle_redirects( $url, $ r, $response );312 $redirect_response = WP_HTTP::handle_redirects( $url, $parsed_args, $response ); 313 313 if ( false !== $redirect_response ) { 314 314 return $redirect_response; 315 315 } 316 316 317 if ( true === $ r['decompress'] && true === WP_Http_Encoding::should_decode( $theHeaders['headers'] ) ) {317 if ( true === $parsed_args['decompress'] && true === WP_Http_Encoding::should_decode( $theHeaders['headers'] ) ) { 318 318 $theBody = WP_Http_Encoding::decompress( $theBody ); 319 319 }
Note: See TracChangeset
for help on using the changeset viewer.