Changeset 45667 for trunk/src/wp-includes/class-http.php
- Timestamp:
- 07/25/2019 12:47:53 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-http.php
r45590 r45667 221 221 } 222 222 223 $ r= wp_parse_args( $args, $defaults );223 $parsed_args = wp_parse_args( $args, $defaults ); 224 224 /** 225 225 * Filters the arguments used in an HTTP request. … … 227 227 * @since 2.7.0 228 228 * 229 * @param array $ rAn array of HTTP request arguments.229 * @param array $parsed_args An array of HTTP request arguments. 230 230 * @param string $url The request URL. 231 231 */ 232 $ r = apply_filters( 'http_request_args', $r, $url );232 $parsed_args = apply_filters( 'http_request_args', $parsed_args, $url ); 233 233 234 234 // The transports decrement this, store a copy of the original value for loop purposes. 235 if ( ! isset( $ r['_redirection'] ) ) {236 $ r['_redirection'] = $r['redirection'];235 if ( ! isset( $parsed_args['_redirection'] ) ) { 236 $parsed_args['_redirection'] = $parsed_args['redirection']; 237 237 } 238 238 … … 252 252 * 253 253 * @param false|array|WP_Error $preempt Whether to preempt an HTTP request's return value. Default false. 254 * @param array $ rHTTP request arguments.254 * @param array $parsed_args HTTP request arguments. 255 255 * @param string $url The request URL. 256 256 */ 257 $pre = apply_filters( 'pre_http_request', false, $ r, $url );257 $pre = apply_filters( 'pre_http_request', false, $parsed_args, $url ); 258 258 259 259 if ( false !== $pre ) { … … 262 262 263 263 if ( function_exists( 'wp_kses_bad_protocol' ) ) { 264 if ( $ r['reject_unsafe_urls'] ) {264 if ( $parsed_args['reject_unsafe_urls'] ) { 265 265 $url = wp_http_validate_url( $url ); 266 266 } … … 275 275 $response = new WP_Error( 'http_request_failed', __( 'A valid URL was not provided.' ) ); 276 276 /** This action is documented in wp-includes/class-http.php */ 277 do_action( 'http_api_debug', $response, 'response', 'Requests', $ r, $url );277 do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url ); 278 278 return $response; 279 279 } … … 282 282 $response = new WP_Error( 'http_request_not_executed', __( 'User has blocked requests through HTTP.' ) ); 283 283 /** This action is documented in wp-includes/class-http.php */ 284 do_action( 'http_api_debug', $response, 'response', 'Requests', $ r, $url );284 do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url ); 285 285 return $response; 286 286 } … … 288 288 // If we are streaming to a file but no filename was given drop it in the WP temp dir 289 289 // and pick its name using the basename of the $url 290 if ( $ r['stream'] ) {291 if ( empty( $ r['filename'] ) ) {292 $ r['filename'] = get_temp_dir() . basename( $url );290 if ( $parsed_args['stream'] ) { 291 if ( empty( $parsed_args['filename'] ) ) { 292 $parsed_args['filename'] = get_temp_dir() . basename( $url ); 293 293 } 294 294 295 295 // Force some settings if we are streaming to a file and check for existence and perms of destination directory 296 $ r['blocking'] = true;297 if ( ! wp_is_writable( dirname( $ r['filename'] ) ) ) {296 $parsed_args['blocking'] = true; 297 if ( ! wp_is_writable( dirname( $parsed_args['filename'] ) ) ) { 298 298 $response = new WP_Error( 'http_request_failed', __( 'Destination directory for file streaming does not exist or is not writable.' ) ); 299 299 /** This action is documented in wp-includes/class-http.php */ 300 do_action( 'http_api_debug', $response, 'response', 'Requests', $ r, $url );300 do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url ); 301 301 return $response; 302 302 } 303 303 } 304 304 305 if ( is_null( $ r['headers'] ) ) {306 $ r['headers'] = array();305 if ( is_null( $parsed_args['headers'] ) ) { 306 $parsed_args['headers'] = array(); 307 307 } 308 308 309 309 // WP allows passing in headers as a string, weirdly. 310 if ( ! is_array( $ r['headers'] ) ) {311 $processedHeaders = WP_Http::processHeaders( $r['headers'] );312 $ r['headers']= $processedHeaders['headers'];310 if ( ! is_array( $parsed_args['headers'] ) ) { 311 $processedHeaders = WP_Http::processHeaders( $parsed_args['headers'] ); 312 $parsed_args['headers'] = $processedHeaders['headers']; 313 313 } 314 314 315 315 // Setup arguments 316 $headers = $ r['headers'];317 $data = $ r['body'];318 $type = $ r['method'];316 $headers = $parsed_args['headers']; 317 $data = $parsed_args['body']; 318 $type = $parsed_args['method']; 319 319 $options = array( 320 'timeout' => $ r['timeout'],321 'useragent' => $ r['user-agent'],322 'blocking' => $ r['blocking'],323 'hooks' => new WP_HTTP_Requests_Hooks( $url, $ r),320 'timeout' => $parsed_args['timeout'], 321 'useragent' => $parsed_args['user-agent'], 322 'blocking' => $parsed_args['blocking'], 323 'hooks' => new WP_HTTP_Requests_Hooks( $url, $parsed_args ), 324 324 ); 325 325 … … 328 328 329 329 // Validate redirected URLs. 330 if ( function_exists( 'wp_kses_bad_protocol' ) && $ r['reject_unsafe_urls'] ) {330 if ( function_exists( 'wp_kses_bad_protocol' ) && $parsed_args['reject_unsafe_urls'] ) { 331 331 $options['hooks']->register( 'requests.before_redirect', array( get_class(), 'validate_redirects' ) ); 332 332 } 333 333 334 if ( $ r['stream'] ) {335 $options['filename'] = $ r['filename'];336 } 337 if ( empty( $ r['redirection'] ) ) {334 if ( $parsed_args['stream'] ) { 335 $options['filename'] = $parsed_args['filename']; 336 } 337 if ( empty( $parsed_args['redirection'] ) ) { 338 338 $options['follow_redirects'] = false; 339 339 } else { 340 $options['redirects'] = $ r['redirection'];340 $options['redirects'] = $parsed_args['redirection']; 341 341 } 342 342 343 343 // Use byte limit, if we can 344 if ( isset( $ r['limit_response_size'] ) ) {345 $options['max_bytes'] = $ r['limit_response_size'];344 if ( isset( $parsed_args['limit_response_size'] ) ) { 345 $options['max_bytes'] = $parsed_args['limit_response_size']; 346 346 } 347 347 348 348 // If we've got cookies, use and convert them to Requests_Cookie. 349 if ( ! empty( $ r['cookies'] ) ) {350 $options['cookies'] = WP_Http::normalize_cookies( $ r['cookies'] );349 if ( ! empty( $parsed_args['cookies'] ) ) { 350 $options['cookies'] = WP_Http::normalize_cookies( $parsed_args['cookies'] ); 351 351 } 352 352 353 353 // SSL certificate handling 354 if ( ! $ r['sslverify'] ) {354 if ( ! $parsed_args['sslverify'] ) { 355 355 $options['verify'] = false; 356 356 $options['verifyname'] = false; 357 357 } else { 358 $options['verify'] = $ r['sslcertificates'];358 $options['verify'] = $parsed_args['sslcertificates']; 359 359 } 360 360 … … 394 394 395 395 // Convert the response into an array 396 $http_response = new WP_HTTP_Requests_Response( $requests_response, $ r['filename'] );396 $http_response = new WP_HTTP_Requests_Response( $requests_response, $parsed_args['filename'] ); 397 397 $response = $http_response->to_array(); 398 398 … … 413 413 * @param string $context Context under which the hook is fired. 414 414 * @param string $class HTTP transport used. 415 * @param array $ rHTTP request arguments.415 * @param array $parsed_args HTTP request arguments. 416 416 * @param string $url The request URL. 417 417 */ 418 do_action( 'http_api_debug', $response, 'response', 'Requests', $ r, $url );418 do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url ); 419 419 if ( is_wp_error( $response ) ) { 420 420 return $response; 421 421 } 422 422 423 if ( ! $ r['blocking'] ) {423 if ( ! $parsed_args['blocking'] ) { 424 424 return array( 425 425 'headers' => array(), … … 440 440 * 441 441 * @param array $response HTTP response. 442 * @param array $ rHTTP request arguments.442 * @param array $parsed_args HTTP request arguments. 443 443 * @param string $url The request URL. 444 444 */ 445 return apply_filters( 'http_response', $response, $ r, $url );445 return apply_filters( 'http_response', $response, $parsed_args, $url ); 446 446 } 447 447 … … 601 601 */ 602 602 public function post( $url, $args = array() ) { 603 $defaults = array( 'method' => 'POST' );604 $ r= wp_parse_args( $args, $defaults );605 return $this->request( $url, $ r);603 $defaults = array( 'method' => 'POST' ); 604 $parsed_args = wp_parse_args( $args, $defaults ); 605 return $this->request( $url, $parsed_args ); 606 606 } 607 607 … … 618 618 */ 619 619 public function get( $url, $args = array() ) { 620 $defaults = array( 'method' => 'GET' );621 $ r= wp_parse_args( $args, $defaults );622 return $this->request( $url, $ r);620 $defaults = array( 'method' => 'GET' ); 621 $parsed_args = wp_parse_args( $args, $defaults ); 622 return $this->request( $url, $parsed_args ); 623 623 } 624 624 … … 635 635 */ 636 636 public function head( $url, $args = array() ) { 637 $defaults = array( 'method' => 'HEAD' );638 $ r= wp_parse_args( $args, $defaults );639 return $this->request( $url, $ r);637 $defaults = array( 'method' => 'HEAD' ); 638 $parsed_args = wp_parse_args( $args, $defaults ); 639 return $this->request( $url, $parsed_args ); 640 640 } 641 641
Note: See TracChangeset
for help on using the changeset viewer.