Merge "Make MapCacheLRU throw errors for bad $field arguments"
[lhc/web/wiklou.git] / includes / http / MWHttpRequest.php
index ac16032..257955c 100644 (file)
@@ -49,7 +49,7 @@ abstract class MWHttpRequest implements LoggerAwareInterface {
        protected $reqHeaders = [];
        protected $url;
        protected $parsedUrl;
-       /** @var callable  */
+       /** @var callable */
        protected $callback;
        protected $maxRedirects = 5;
        protected $followRedirects = false;
@@ -79,7 +79,7 @@ abstract class MWHttpRequest implements LoggerAwareInterface {
        protected $profileName;
 
        /**
-        * @var LoggerInterface;
+        * @var LoggerInterface
         */
        protected $logger;
 
@@ -87,7 +87,7 @@ abstract class MWHttpRequest implements LoggerAwareInterface {
         * @param string $url Url to use. If protocol-relative, will be expanded to an http:// URL
         * @param array $options (optional) extra params to pass (see Http::request())
         * @param string $caller The method making this request, for profiling
-        * @param Profiler $profiler An instance of the profiler for profiling, or null
+        * @param Profiler|null $profiler An instance of the profiler for profiling, or null
         */
        public function __construct(
                $url, array $options = [], $caller = __METHOD__, $profiler = null
@@ -175,13 +175,16 @@ abstract class MWHttpRequest implements LoggerAwareInterface {
         * Generate a new request object
         * Deprecated: @see HttpRequestFactory::create
         * @param string $url Url to use
-        * @param array $options (optional) extra params to pass (see Http::request())
+        * @param array|null $options (optional) extra params to pass (see Http::request())
         * @param string $caller The method making this request, for profiling
         * @throws DomainException
         * @return MWHttpRequest
         * @see MWHttpRequest::__construct
         */
-       public static function factory( $url, array $options = [], $caller = __METHOD__ ) {
+       public static function factory( $url, array $options = null, $caller = __METHOD__ ) {
+               if ( $options === null ) {
+                       $options = [];
+               }
                return \MediaWiki\MediaWikiServices::getInstance()
                        ->getHttpRequestFactory()
                        ->create( $url, $options, $caller );
@@ -329,6 +332,7 @@ abstract class MWHttpRequest implements LoggerAwareInterface {
                if ( is_null( $callback ) ) {
                        $callback = [ $this, 'read' ];
                } elseif ( !is_callable( $callback ) ) {
+                       $this->status->fatal( 'http-internal-error' );
                        throw new InvalidArgumentException( __METHOD__ . ': invalid callback' );
                }
                $this->callback = $callback;
@@ -384,6 +388,11 @@ abstract class MWHttpRequest implements LoggerAwareInterface {
        protected function parseHeader() {
                $lastname = "";
 
+               // Failure without (valid) headers gets a response status of zero
+               if ( !$this->status->isOK() ) {
+                       $this->respStatus = '0';
+               }
+
                foreach ( $this->headerList as $header ) {
                        if ( preg_match( "#^HTTP/([0-9.]+) (.*)#", $header, $match ) ) {
                                $this->respVersion = $match[1];