Make WordPress Core

Changeset 20208


Ignore:
Timestamp:
03/18/2012 05:00:05 AM (13 years ago)
Author:
dd32
Message:

WP_HTTP: Curl: Handle Redirections in PHP rather than internally in Curl, Simplifies code flow between safe_mode On and Off, and works around certain bugs. Props simonwheatley for initial patch. Fixes #20219, Fixes #17490

File:
1 edited

Legend:

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

    r20207 r20208  
    10391039        curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, $ssl_verify );
    10401040        curl_setopt( $handle, CURLOPT_USERAGENT, $r['user-agent'] );
    1041         curl_setopt( $handle, CURLOPT_MAXREDIRS, $r['redirection'] );
     1041        // The option doesn't work with safe mode or when open_basedir is set, and there's a
     1042        // bug #17490 with redirected POST requests, so handle redirections outside Curl.
     1043        curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, false );
    10421044
    10431045        switch ( $r['method'] ) {
     
    10761078        }
    10771079
    1078         // The option doesn't work with safe mode or when open_basedir is set.
    1079         if ( !ini_get('safe_mode') && !ini_get('open_basedir') && 0 !== $r['_redirection'] )
    1080             curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, true );
    1081 
    10821080        if ( !empty( $r['headers'] ) ) {
    10831081            // cURL expects full header strings in each element
     
    11121110            $theBody = $theResponse;
    11131111
    1114         // If no response, and It's not a HEAD request with valid headers returned
    1115         if ( 0 == strlen($theResponse) && ('HEAD' != $r['method'] || empty($this->headers)) ) {
     1112        // If no response
     1113        if ( 0 == strlen($theResponse) && empty( $theHeaders ) ) {
    11161114            if ( $curl_error = curl_error($handle) )
    11171115                return new WP_Error('http_request_failed', $curl_error);
     
    11321130
    11331131        // See #11305 - When running under safe mode, redirection is disabled above. Handle it manually.
    1134         if ( ! empty( $theHeaders['headers']['location'] ) && ( ini_get( 'safe_mode' ) || ini_get( 'open_basedir' ) ) && 0 !== $r['_redirection'] ) {
     1132        if ( ! empty( $theHeaders['headers']['location'] ) && 0 !== $r['_redirection'] ) { // _redirection: The requested number of redirections
    11351133            if ( $r['redirection']-- > 0 ) {
    11361134                return $this->request( $theHeaders['headers']['location'], $r );
Note: See TracChangeset for help on using the changeset viewer.