MultiHttpClient: Don't relay the end-of-headers line
authorBrad Jorsch <bjorsch@wikimedia.org>
Tue, 19 Feb 2019 18:54:03 +0000 (13:54 -0500)
committerUmherirrender <umherirrender_de.wp@web.de>
Tue, 19 Feb 2019 21:20:30 +0000 (21:20 +0000)
The callback registered by CURLOPT_HEADERFUNCTION is called for the
empty line that separates the headers from the body, as well as all the
actual headers. In this case, the $header string will be "\r\n".

It turns out that HHVM ignores a call to header() when passed a string
that's empty after trimming whitespace, while Zend PHP only ignores the
call when the string is empty before trimming whitespace. This later
causes problems when headers_list() is used expecting all strings
returned to contain a colon.

Bug: T216086
Change-Id: I07937b17beb06788166266fbb1ea1bbf456761e3

includes/libs/MultiHttpClient.php

index 6ce8f45..536177e 100644 (file)
@@ -384,7 +384,7 @@ class MultiHttpClient implements LoggerAwareInterface {
 
                curl_setopt( $ch, CURLOPT_HEADERFUNCTION,
                        function ( $ch, $header ) use ( &$req ) {
-                               if ( !empty( $req['flags']['relayResponseHeaders'] ) ) {
+                               if ( !empty( $req['flags']['relayResponseHeaders'] ) && trim( $header ) !== '' ) {
                                        header( $header );
                                }
                                $length = strlen( $header );