X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2FMultiHttpClient.php;h=fdcbf4904b7878ee4fbb680fdd31238dfac9409d;hb=32628487e17c27f3437d44bd54edb8438e837b82;hp=331f2d5e99011082109b7807510b9919c5d734eb;hpb=d716155c8b2d6e4a51a4110195cee7a1794846e8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/MultiHttpClient.php b/includes/libs/MultiHttpClient.php index 331f2d5e99..fdcbf4904b 100644 --- a/includes/libs/MultiHttpClient.php +++ b/includes/libs/MultiHttpClient.php @@ -35,6 +35,8 @@ * use application/x-www-form-urlencoded (headers sent automatically) * - stream : resource to stream the HTTP response body to * - proxy : HTTP proxy to use + * - flags : map of boolean flags which supports: + * - relayResponseHeaders : write out header via header() * Request maps can use integer index 0 instead of 'method' and 1 instead of 'url'. * * @author Aaron Schulz @@ -104,7 +106,7 @@ class MultiHttpClient { * - reqTimeout : post-connection timeout per request (seconds) * @return array Response array for request */ - final public function run( array $req, array $opts = [] ) { + public function run( array $req, array $opts = [] ) { return $this->runMulti( [ $req ], $opts )[0]['response']; } @@ -172,6 +174,7 @@ class MultiHttpClient { $req['body'] = ''; $req['headers']['content-length'] = 0; } + $req['flags'] = isset( $req['flags'] ) ? $req['flags'] : []; $handles[$index] = $this->getCurlHandle( $req, $opts ); if ( count( $reqs ) > 1 ) { // https://github.com/guzzle/guzzle/issues/349 @@ -348,7 +351,7 @@ class MultiHttpClient { // In PHP 5.2 and later, '@' is interpreted as a file upload if POSTFIELDS // is an array, but not if it's a string. So convert $req['body'] to a string // for safety. - $req['body'] = wfArrayToCgi( $req['body'] ); + $req['body'] = http_build_query( $req['body'] ); } curl_setopt( $ch, CURLOPT_POSTFIELDS, $req['body'] ); } else { @@ -373,6 +376,9 @@ class MultiHttpClient { curl_setopt( $ch, CURLOPT_HEADERFUNCTION, function ( $ch, $header ) use ( &$req ) { + if ( !empty( $req['flags']['relayResponseHeaders'] ) ) { + header( $header ); + } $length = strlen( $header ); $matches = []; if ( preg_match( "/^(HTTP\/1\.[01]) (\d{3}) (.*)/", $header, $matches ) ) {