- # Don't return the text of error messages, return false on error
- $retcode = curl_getinfo( $c, CURLINFO_HTTP_CODE );
- if ( $retcode != 200 ) {
- wfDebug( __METHOD__ . ": HTTP return code $retcode\n" );
- $status = Status::newFatal( "HTTP return code $retcode\n" );
- }
- # Don't return truncated output
- $errno = curl_errno( $c );
- if ( $errno != CURLE_OK ) {
- $errstr = curl_error( $c );
- wfDebug( __METHOD__ . ": CURL error code $errno: $errstr\n" );
+ if ( $this->headers_only ) {
+ $headers = explode( "\n", $status->value );
+ $headerArray = array();
+ foreach ( $headers as $header ) {
+ if ( !strlen( trim( $header ) ) )
+ continue;
+ $headerParts = explode( ':', $header, 2 );
+ if ( count( $headerParts ) == 1 ) {
+ $headerArray[] = trim( $header );
+ } else {
+ list( $key, $val ) = $headerParts;
+ $headerArray[trim( $key )] = trim( $val );
+ }
+ }
+ $status->value = $headerArray;
+ } else {
+ # Don't return the text of error messages, return false on error
+ $retcode = curl_getinfo( $c, CURLINFO_HTTP_CODE );
+ if ( $retcode != 200 ) {
+ wfDebug( __METHOD__ . ": HTTP return code $retcode\n" );
+ $status = Status::newFatal( "HTTP return code $retcode\n" );
+ }
+ # Don't return truncated output
+ $errno = curl_errno( $c );
+ if ( $errno != CURLE_OK ) {
+ $errstr = curl_error( $c );
+ wfDebug( __METHOD__ . ": CURL error code $errno: $errstr\n" );