Fix problem of incorrect Status message use.
authorMark A. Hershberger <mah@users.mediawiki.org>
Tue, 9 Feb 2010 08:23:09 +0000 (08:23 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Tue, 9 Feb 2010 08:23:09 +0000 (08:23 +0000)
Uncovered an additional problem with HTTP error messages and PhpHttpRequest

includes/HttpFunctions.php
maintenance/tests/HttpTest.php

index 9012c96..12508ab 100644 (file)
@@ -334,8 +334,10 @@ class HttpRequest {
                }
 
                if((int)$this->respStatus !== 200) {
-                       $this->status->fatal("http-bad-status", explode(" ", $this->respStatus, 2));
+                       list( $code, $message ) = explode(" ", $this->respStatus, 2);
+                       $this->status->fatal("http-bad-status", $code, $message );
                }
+
                $this->parseCookies();
        }
 
@@ -753,6 +755,7 @@ class PhpHttpRequest extends HttpRequest {
 
                $options['method'] = $this->method;
                $options['timeout'] = $this->timeout;
+               $options['ignore_errors'] = true; /* the only way to get 404s, etc */
                $options['header'] = implode("\r\n", $this->getHeaderList());
                // Note that at some future point we may want to support
                // HTTP/1.1, but we'd have to write support for chunking
@@ -787,19 +790,21 @@ class PhpHttpRequest extends HttpRequest {
                }
                $this->headerList = $result['wrapper_data'];
 
-               while ( !feof( $fh ) ) {
-                       $buf = fread( $fh, 8192 );
-                       if ( $buf === false ) {
-                               $this->status->fatal( 'http-read-error' );
-                               break;
-                       }
-                       if ( strlen( $buf ) ) {
-                               call_user_func( $this->callback, $fh, $buf );
+               $this->parseHeader();
+               if($this->status->isOK()) {
+                       while ( !feof( $fh ) ) {
+                               $buf = fread( $fh, 8192 );
+                               if ( $buf === false ) {
+                                       $this->status->fatal( 'http-read-error' );
+                                       break;
+                               }
+                               if ( strlen( $buf ) ) {
+                                       call_user_func( $this->callback, $fh, $buf );
+                               }
                        }
                }
                fclose( $fh );
 
-               $this->parseHeader();
                return $this->status;
        }
 }
index 1488d7f..5c3cf50 100644 (file)
@@ -112,6 +112,11 @@ class HttpTest extends PhpUnit_Framework_TestCase {
 
                $r = HTTP::get( "http://www.example.com/this-file-does-not-exist", $timeout);
                $this->assertFalse($r, "False on 404s");
+
+
+               $r = HttpRequest::factory( "http://www.example.com/this-file-does-not-exist" );
+               $er = $r->execute();
+               $this->assertRegexp("/404 Not Found/", $er->getWikiText());
        }
 
        function testFailureDefault() {
@@ -550,5 +555,4 @@ class HttpTest extends PhpUnit_Framework_TestCase {
                Http::$httpEngine = 'curl';
                self::runCookieRequests();
        }
-
 }
\ No newline at end of file