WordPress.org

Make WordPress Core

Changeset 23603


Ignore:
Timestamp:
03/04/13 04:10:36 (14 months ago)
Author:
dd32
Message:

WP_HTTP: Funnel all redirect requests through WP_HTTP::request() via wp_remote_request() to ensure that the proper transport is chosen for redirects.
This change also moves PHP Streams from redirecting internally, to us handling the redirections in PHP, which brings a more consistent behaviour between transports.
Fixes #23682

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/class-http.php

    r23602 r23603  
    780780        if ( isset($arrHeaders['headers']['location']) && 0 !== $r['_redirection'] ) { 
    781781            if ( $r['redirection']-- > 0 ) { 
    782                 return $this->request( WP_HTTP::make_absolute_url( $arrHeaders['headers']['location'], $url ), $r); 
     782                return wp_remote_request( WP_HTTP::make_absolute_url( $arrHeaders['headers']['location'], $url ), $r); 
    783783            } else { 
    784784                return new WP_Error('http_request_failed', __('Too many redirects.')); 
     
    890890                'method' => strtoupper($r['method']), 
    891891                'user_agent' => $r['user-agent'], 
    892                 'max_redirects' => $r['redirection'] + 1, // See #11557 
     892                'max_redirects' => 0, // Follow no redirects 
     893                'follow_redirects' => false, 
    893894                'protocol_version' => (float) $r['httpversion'], 
    894895                'header' => $strHeaders, 
     
    963964            $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']); 
    964965 
    965         // Streams does not provide an error code which we can use to see why the request stream stopped. 
    966         // We can however test to see if a location header is present and return based on that. 
    967         if ( isset($processedHeaders['headers']['location']) && 0 !== $args['_redirection'] ) 
    968             return new WP_Error('http_request_failed', __('Too many redirects.')); 
     966        if ( ! empty( $processedHeaders['headers']['location'] ) && 0 !== $r['_redirection'] ) { // _redirection: The requested number of redirections 
     967            if ( $r['redirection']-- > 0 ) { 
     968                return wp_remote_request( WP_HTTP::make_absolute_url( $processedHeaders['headers']['location'], $url ), $r ); 
     969            } else { 
     970                return new WP_Error( 'http_request_failed', __( 'Too many redirects.' ) ); 
     971            } 
     972        } 
    969973 
    970974        if ( ! empty( $strResponse ) && isset( $processedHeaders['headers']['transfer-encoding'] ) && 'chunked' == $processedHeaders['headers']['transfer-encoding'] ) 
     
    11811185        if ( ! empty( $theHeaders['headers']['location'] ) && 0 !== $r['_redirection'] ) { // _redirection: The requested number of redirections 
    11821186            if ( $r['redirection']-- > 0 ) { 
    1183                 return $this->request( WP_HTTP::make_absolute_url( $theHeaders['headers']['location'], $url ), $r ); 
     1187                return wp_remote_request( WP_HTTP::make_absolute_url( $theHeaders['headers']['location'], $url ), $r ); 
    11841188            } else { 
    11851189                return new WP_Error( 'http_request_failed', __( 'Too many redirects.' ) ); 
Note: See TracChangeset for help on using the changeset viewer.