r62174 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62173‎ | r62174 | r62175 >
Date:08:23, 9 February 2010
Author:mah
Status:ok
Tags:
Comment:
Fix problem of incorrect Status message use.
Uncovered an additional problem with HTTP error messages and PhpHttpRequest
Modified paths:
  • /trunk/phase3/includes/HttpFunctions.php (modified) (history)
  • /trunk/phase3/maintenance/tests/HttpTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/HttpTest.php
@@ -112,6 +112,11 @@
113113
114114 $r = HTTP::get( "http://www.example.com/this-file-does-not-exist", $timeout);
115115 $this->assertFalse($r, "False on 404s");
 116+
 117+
 118+ $r = HttpRequest::factory( "http://www.example.com/this-file-does-not-exist" );
 119+ $er = $r->execute();
 120+ $this->assertRegexp("/404 Not Found/", $er->getWikiText());
116121 }
117122
118123 function testFailureDefault() {
@@ -550,5 +555,4 @@
551556 Http::$httpEngine = 'curl';
552557 self::runCookieRequests();
553558 }
554 -
555559 }
\ No newline at end of file
Index: trunk/phase3/includes/HttpFunctions.php
@@ -334,8 +334,10 @@
335335 }
336336
337337 if((int)$this->respStatus !== 200) {
338 - $this->status->fatal("http-bad-status", explode(" ", $this->respStatus, 2));
 338+ list( $code, $message ) = explode(" ", $this->respStatus, 2);
 339+ $this->status->fatal("http-bad-status", $code, $message );
339340 }
 341+
340342 $this->parseCookies();
341343 }
342344
@@ -753,6 +755,7 @@
754756
755757 $options['method'] = $this->method;
756758 $options['timeout'] = $this->timeout;
 759+ $options['ignore_errors'] = true; /* the only way to get 404s, etc */
757760 $options['header'] = implode("\r\n", $this->getHeaderList());
758761 // Note that at some future point we may want to support
759762 // HTTP/1.1, but we'd have to write support for chunking
@@ -787,19 +790,21 @@
788791 }
789792 $this->headerList = $result['wrapper_data'];
790793
791 - while ( !feof( $fh ) ) {
792 - $buf = fread( $fh, 8192 );
793 - if ( $buf === false ) {
794 - $this->status->fatal( 'http-read-error' );
795 - break;
 794+ $this->parseHeader();
 795+ if($this->status->isOK()) {
 796+ while ( !feof( $fh ) ) {
 797+ $buf = fread( $fh, 8192 );
 798+ if ( $buf === false ) {
 799+ $this->status->fatal( 'http-read-error' );
 800+ break;
 801+ }
 802+ if ( strlen( $buf ) ) {
 803+ call_user_func( $this->callback, $fh, $buf );
 804+ }
796805 }
797 - if ( strlen( $buf ) ) {
798 - call_user_func( $this->callback, $fh, $buf );
799 - }
800806 }
801807 fclose( $fh );
802808
803 - $this->parseHeader();
804809 return $this->status;
805810 }
806811 }

Status & tagging log