From: Mark A. Hershberger Date: Tue, 9 Feb 2010 08:23:09 +0000 (+0000) Subject: Fix problem of incorrect Status message use. X-Git-Tag: 1.31.0-rc.0~37858 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=d74e55fc0937ba81cfc4d3e7b9546edee926d987;p=lhc%2Fweb%2Fwiklou.git Fix problem of incorrect Status message use. Uncovered an additional problem with HTTP error messages and PhpHttpRequest --- diff --git a/includes/HttpFunctions.php b/includes/HttpFunctions.php index 9012c96c60..12508abe32 100644 --- a/includes/HttpFunctions.php +++ b/includes/HttpFunctions.php @@ -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; } } diff --git a/maintenance/tests/HttpTest.php b/maintenance/tests/HttpTest.php index 1488d7fd88..5c3cf50f5e 100644 --- a/maintenance/tests/HttpTest.php +++ b/maintenance/tests/HttpTest.php @@ -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