3 * Various HTTP related functions.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
29 * Various HTTP related functions
33 static $httpEngine = false;
36 * Perform an HTTP request
38 * @param string $method HTTP method. Usually GET/POST
39 * @param string $url full URL to act on. If protocol-relative, will be expanded to an http:// URL
40 * @param array $options options to pass to MWHttpRequest object.
41 * Possible keys for the array:
42 * - timeout Timeout length in seconds
43 * - postData An array of key-value pairs or a url-encoded form data
44 * - proxy The proxy to use.
45 * Otherwise it will use $wgHTTPProxy (if set)
46 * Otherwise it will use the environment variable "http_proxy" (if set)
47 * - noProxy Don't use any proxy at all. Takes precedence over proxy value(s).
48 * - sslVerifyHost (curl only) Verify hostname against certificate
49 * - sslVerifyCert (curl only) Verify SSL certificate
50 * - caInfo (curl only) Provide CA information
51 * - maxRedirects Maximum number of redirects to follow (defaults to 5)
52 * - followRedirects Whether to follow redirects (defaults to false).
53 * Note: this should only be used when the target URL is trusted,
54 * to avoid attacks on intranet services accessible by HTTP.
55 * - userAgent A user agent, if you want to override the default
56 * MediaWiki/$wgVersion
57 * @return Mixed: (bool)false on failure or a string on success
59 public static function request( $method, $url, $options = array() ) {
60 wfDebug( "HTTP: $method: $url\n" );
61 wfProfileIn( __METHOD__
. "-$method" );
63 $options['method'] = strtoupper( $method );
65 if ( !isset( $options['timeout'] ) ) {
66 $options['timeout'] = 'default';
69 $req = MWHttpRequest
::factory( $url, $options );
70 $status = $req->execute();
72 if ( $status->isOK() ) {
73 $content = $req->getContent();
74 wfProfileOut( __METHOD__
. "-$method" );
77 wfProfileOut( __METHOD__
. "-$method" );
83 * Simple wrapper for Http::request( 'GET' )
84 * @see Http::request()
87 * @param $timeout string
88 * @param $options array
91 public static function get( $url, $timeout = 'default', $options = array() ) {
92 $options['timeout'] = $timeout;
93 return Http
::request( 'GET', $url, $options );
97 * Simple wrapper for Http::request( 'POST' )
98 * @see Http::request()
101 * @param $options array
104 public static function post( $url, $options = array() ) {
105 return Http
::request( 'POST', $url, $options );
109 * Check if the URL can be served by localhost
111 * @param string $url full url to check
114 public static function isLocalURL( $url ) {
115 global $wgCommandLineMode, $wgConf;
117 if ( $wgCommandLineMode ) {
123 if ( preg_match( '!^http://([\w.-]+)[/:].*$!', $url, $matches ) ) {
126 $domainParts = explode( '.', $host );
127 // Check if this domain or any superdomain is listed in $wgConf as a local virtual host
128 $domainParts = array_reverse( $domainParts );
131 for ( $i = 0; $i < count( $domainParts ); $i++
) {
132 $domainPart = $domainParts[$i];
134 $domain = $domainPart;
136 $domain = $domainPart . '.' . $domain;
139 if ( $wgConf->isLocalVHost( $domain ) ) {
149 * A standard user-agent we can use for external requests.
152 public static function userAgent() {
154 return "MediaWiki/$wgVersion";
158 * Checks that the given URI is a valid one. Hardcoding the
159 * protocols, because we only want protocols that both cURL
162 * file:// should not be allowed here for security purpose (r67684)
164 * @todo FIXME this is wildly inaccurate and fails to actually check most stuff
166 * @param $uri Mixed: URI to check for validity
169 public static function isValidURI( $uri ) {
171 '/^https?:\/\/[^\/\s]\S*$/D',
178 * This wrapper class will call out to curl (if available) or fallback
179 * to regular PHP if necessary for handling internal HTTP requests.
181 * Renamed from HttpRequest to MWHttpRequest to avoid conflict with
182 * PHP's HTTP extension.
184 class MWHttpRequest
{
185 const SUPPORTS_FILE_POSTS
= false;
188 protected $timeout = 'default';
189 protected $headersOnly = null;
190 protected $postData = null;
191 protected $proxy = null;
192 protected $noProxy = false;
193 protected $sslVerifyHost = true;
194 protected $sslVerifyCert = true;
195 protected $caInfo = null;
196 protected $method = "GET";
197 protected $reqHeaders = array();
199 protected $parsedUrl;
201 protected $maxRedirects = 5;
202 protected $followRedirects = false;
207 protected $cookieJar;
209 protected $headerList = array();
210 protected $respVersion = "0.9";
211 protected $respStatus = "200 Ok";
212 protected $respHeaders = array();
217 * @param string $url url to use. If protocol-relative, will be expanded to an http:// URL
218 * @param array $options (optional) extra params to pass (see Http::request())
220 protected function __construct( $url, $options = array() ) {
221 global $wgHTTPTimeout;
223 $this->url
= wfExpandUrl( $url, PROTO_HTTP
);
224 $this->parsedUrl
= wfParseUrl( $this->url
);
226 if ( !$this->parsedUrl ||
!Http
::isValidURI( $this->url
) ) {
227 $this->status
= Status
::newFatal( 'http-invalid-url' );
229 $this->status
= Status
::newGood( 100 ); // continue
232 if ( isset( $options['timeout'] ) && $options['timeout'] != 'default' ) {
233 $this->timeout
= $options['timeout'];
235 $this->timeout
= $wgHTTPTimeout;
237 if( isset( $options['userAgent'] ) ) {
238 $this->setUserAgent( $options['userAgent'] );
241 $members = array( "postData", "proxy", "noProxy", "sslVerifyHost", "caInfo",
242 "method", "followRedirects", "maxRedirects", "sslVerifyCert", "callback" );
244 foreach ( $members as $o ) {
245 if ( isset( $options[$o] ) ) {
246 // ensure that MWHttpRequest::method is always
247 // uppercased. Bug 36137
248 if ( $o == 'method' ) {
249 $options[$o] = strtoupper( $options[$o] );
251 $this->$o = $options[$o];
255 if ( $this->noProxy
) {
256 $this->proxy
= ''; // noProxy takes precedence
261 * Simple function to test if we can make any sort of requests at all, using
265 public static function canMakeRequests() {
266 return function_exists( 'curl_init' ) ||
wfIniGetBool( 'allow_url_fopen' );
270 * Generate a new request object
271 * @param string $url url to use
272 * @param array $options (optional) extra params to pass (see Http::request())
273 * @throws MWException
274 * @return CurlHttpRequest|PhpHttpRequest
275 * @see MWHttpRequest::__construct
277 public static function factory( $url, $options = null ) {
278 if ( !Http
::$httpEngine ) {
279 Http
::$httpEngine = function_exists( 'curl_init' ) ?
'curl' : 'php';
280 } elseif ( Http
::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) {
281 throw new MWException( __METHOD__
. ': curl (http://php.net/curl) is not installed, but' .
282 ' Http::$httpEngine is set to "curl"' );
285 switch( Http
::$httpEngine ) {
287 return new CurlHttpRequest( $url, $options );
289 if ( !wfIniGetBool( 'allow_url_fopen' ) ) {
290 throw new MWException( __METHOD__
. ': allow_url_fopen needs to be enabled for pure PHP' .
291 ' http requests to work. If possible, curl should be used instead. See http://php.net/curl.' );
293 return new PhpHttpRequest( $url, $options );
295 throw new MWException( __METHOD__
. ': The setting of Http::$httpEngine is not valid.' );
300 * Get the body, or content, of the response to the request
304 public function getContent() {
305 return $this->content
;
309 * Set the parameters of the request
312 * @todo overload the args param
314 public function setData( $args ) {
315 $this->postData
= $args;
319 * Take care of setting up the proxy (do nothing if "noProxy" is set)
323 public function proxySetup() {
326 // If there is an explicit proxy set and proxies are not disabled, then use it
327 if ( $this->proxy
&& !$this->noProxy
) {
331 // Otherwise, fallback to $wgHTTPProxy/http_proxy (when set) if this is not a machine
332 // local URL and proxies are not disabled
333 if ( Http
::isLocalURL( $this->url
) ||
$this->noProxy
) {
335 } elseif ( $wgHTTPProxy ) {
336 $this->proxy
= $wgHTTPProxy;
337 } elseif ( getenv( "http_proxy" ) ) {
338 $this->proxy
= getenv( "http_proxy" );
343 * Set the referrer header
345 public function setReferer( $url ) {
346 $this->setHeader( 'Referer', $url );
353 public function setUserAgent( $UA ) {
354 $this->setHeader( 'User-Agent', $UA );
358 * Set an arbitrary header
362 public function setHeader( $name, $value ) {
363 // I feel like I should normalize the case here...
364 $this->reqHeaders
[$name] = $value;
368 * Get an array of the headers
371 public function getHeaderList() {
374 if ( $this->cookieJar
) {
375 $this->reqHeaders
['Cookie'] =
376 $this->cookieJar
->serializeToHttpRequest(
377 $this->parsedUrl
['path'],
378 $this->parsedUrl
['host']
382 foreach ( $this->reqHeaders
as $name => $value ) {
383 $list[] = "$name: $value";
390 * Set a read callback to accept data read from the HTTP request.
391 * By default, data is appended to an internal buffer which can be
392 * retrieved through $req->getContent().
394 * To handle data as it comes in -- especially for large files that
395 * would not fit in memory -- you can instead set your own callback,
396 * in the form function($resource, $buffer) where the first parameter
397 * is the low-level resource being read (implementation specific),
398 * and the second parameter is the data buffer.
400 * You MUST return the number of bytes handled in the buffer; if fewer
401 * bytes are reported handled than were passed to you, the HTTP fetch
404 * @param $callback Callback
405 * @throws MWException
407 public function setCallback( $callback ) {
408 if ( !is_callable( $callback ) ) {
409 throw new MWException( 'Invalid MwHttpRequest callback' );
411 $this->callback
= $callback;
415 * A generic callback to read the body of the response from a remote
419 * @param $content String
422 public function read( $fh, $content ) {
423 $this->content
.= $content;
424 return strlen( $content );
428 * Take care of whatever is necessary to perform the URI request.
432 public function execute() {
435 wfProfileIn( __METHOD__
);
439 if ( strtoupper( $this->method
) == "HEAD" ) {
440 $this->headersOnly
= true;
443 if ( is_object( $wgTitle ) && !isset( $this->reqHeaders
['Referer'] ) ) {
444 $this->setReferer( wfExpandUrl( $wgTitle->getFullURL(), PROTO_CURRENT
) );
447 $this->proxySetup(); // set up any proxy as needed
449 if ( !$this->callback
) {
450 $this->setCallback( array( $this, 'read' ) );
453 if ( !isset( $this->reqHeaders
['User-Agent'] ) ) {
454 $this->setUserAgent( Http
::userAgent() );
457 wfProfileOut( __METHOD__
);
461 * Parses the headers, including the HTTP status code and any
462 * Set-Cookie headers. This function expects the headers to be
463 * found in an array in the member variable headerList.
465 protected function parseHeader() {
466 wfProfileIn( __METHOD__
);
470 foreach ( $this->headerList
as $header ) {
471 if ( preg_match( "#^HTTP/([0-9.]+) (.*)#", $header, $match ) ) {
472 $this->respVersion
= $match[1];
473 $this->respStatus
= $match[2];
474 } elseif ( preg_match( "#^[ \t]#", $header ) ) {
475 $last = count( $this->respHeaders
[$lastname] ) - 1;
476 $this->respHeaders
[$lastname][$last] .= "\r\n$header";
477 } elseif ( preg_match( "#^([^:]*):[\t ]*(.*)#", $header, $match ) ) {
478 $this->respHeaders
[strtolower( $match[1] )][] = $match[2];
479 $lastname = strtolower( $match[1] );
483 $this->parseCookies();
485 wfProfileOut( __METHOD__
);
489 * Sets HTTPRequest status member to a fatal value with the error
490 * message if the returned integer value of the status code was
491 * not successful (< 300) or a redirect (>=300 and < 400). (see
492 * RFC2616, section 10,
493 * http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for a
494 * list of status codes.)
496 protected function setStatus() {
497 if ( !$this->respHeaders
) {
498 $this->parseHeader();
501 if ( (int)$this->respStatus
> 399 ) {
502 list( $code, $message ) = explode( " ", $this->respStatus
, 2 );
503 $this->status
->fatal( "http-bad-status", $code, $message );
508 * Get the integer value of the HTTP status code (e.g. 200 for "200 Ok")
509 * (see RFC2616, section 10, http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
510 * for a list of status codes.)
514 public function getStatus() {
515 if ( !$this->respHeaders
) {
516 $this->parseHeader();
519 return (int)$this->respStatus
;
523 * Returns true if the last status code was a redirect.
527 public function isRedirect() {
528 if ( !$this->respHeaders
) {
529 $this->parseHeader();
532 $status = (int)$this->respStatus
;
534 if ( $status >= 300 && $status <= 303 ) {
542 * Returns an associative array of response headers after the
543 * request has been executed. Because some headers
544 * (e.g. Set-Cookie) can appear more than once the, each value of
545 * the associative array is an array of the values given.
549 public function getResponseHeaders() {
550 if ( !$this->respHeaders
) {
551 $this->parseHeader();
554 return $this->respHeaders
;
558 * Returns the value of the given response header.
560 * @param $header String
563 public function getResponseHeader( $header ) {
564 if ( !$this->respHeaders
) {
565 $this->parseHeader();
568 if ( isset( $this->respHeaders
[strtolower ( $header ) ] ) ) {
569 $v = $this->respHeaders
[strtolower ( $header ) ];
570 return $v[count( $v ) - 1];
577 * Tells the MWHttpRequest object to use this pre-loaded CookieJar.
579 * @param $jar CookieJar
581 public function setCookieJar( $jar ) {
582 $this->cookieJar
= $jar;
586 * Returns the cookie jar in use.
590 public function getCookieJar() {
591 if ( !$this->respHeaders
) {
592 $this->parseHeader();
595 return $this->cookieJar
;
599 * Sets a cookie. Used before a request to set up any individual
600 * cookies. Used internally after a request to parse the
601 * Set-Cookie headers.
607 public function setCookie( $name, $value = null, $attr = null ) {
608 if ( !$this->cookieJar
) {
609 $this->cookieJar
= new CookieJar
;
612 $this->cookieJar
->setCookie( $name, $value, $attr );
616 * Parse the cookies in the response headers and store them in the cookie jar.
618 protected function parseCookies() {
619 wfProfileIn( __METHOD__
);
621 if ( !$this->cookieJar
) {
622 $this->cookieJar
= new CookieJar
;
625 if ( isset( $this->respHeaders
['set-cookie'] ) ) {
626 $url = parse_url( $this->getFinalUrl() );
627 foreach ( $this->respHeaders
['set-cookie'] as $cookie ) {
628 $this->cookieJar
->parseCookieResponseHeader( $cookie, $url['host'] );
632 wfProfileIn( __METHOD__
);
636 * Returns the final URL after all redirections.
638 * Relative values of the "Location" header are incorrect as stated in RFC, however they do happen and modern browsers support them.
639 * This function loops backwards through all locations in order to build the proper absolute URI - Marooned at wikia-inc.com
641 * Note that the multiple Location: headers are an artifact of CURL -- they
642 * shouldn't actually get returned this way. Rewrite this when bug 29232 is
643 * taken care of (high-level redirect handling rewrite).
647 public function getFinalUrl() {
648 $headers = $this->getResponseHeaders();
650 //return full url (fix for incorrect but handled relative location)
651 if ( isset( $headers[ 'location' ] ) ) {
652 $locations = $headers[ 'location' ];
654 $foundRelativeURI = false;
655 $countLocations = count( $locations );
657 for ( $i = $countLocations - 1; $i >= 0; $i-- ) {
658 $url = parse_url( $locations[ $i ] );
660 if ( isset( $url['host'] ) ) {
661 $domain = $url[ 'scheme' ] . '://' . $url[ 'host' ];
662 break; //found correct URI (with host)
664 $foundRelativeURI = true;
668 if ( $foundRelativeURI ) {
670 return $domain . $locations[ $countLocations - 1 ];
672 $url = parse_url( $this->url
);
673 if ( isset($url[ 'host' ]) ) {
674 return $url[ 'scheme' ] . '://' . $url[ 'host' ] . $locations[ $countLocations - 1 ];
678 return $locations[ $countLocations - 1 ];
686 * Returns true if the backend can follow redirects. Overridden by the
690 public function canFollowRedirects() {
696 * MWHttpRequest implemented using internal curl compiled into PHP
698 class CurlHttpRequest
extends MWHttpRequest
{
699 const SUPPORTS_FILE_POSTS
= true;
701 static $curlMessageMap = array(
702 6 => 'http-host-unreachable',
703 28 => 'http-timed-out'
706 protected $curlOptions = array();
707 protected $headerText = "";
714 protected function readHeader( $fh, $content ) {
715 $this->headerText
.= $content;
716 return strlen( $content );
719 public function execute() {
720 wfProfileIn( __METHOD__
);
724 if ( !$this->status
->isOK() ) {
725 wfProfileOut( __METHOD__
);
726 return $this->status
;
729 $this->curlOptions
[CURLOPT_PROXY
] = $this->proxy
;
730 $this->curlOptions
[CURLOPT_TIMEOUT
] = $this->timeout
;
731 $this->curlOptions
[CURLOPT_HTTP_VERSION
] = CURL_HTTP_VERSION_1_0
;
732 $this->curlOptions
[CURLOPT_WRITEFUNCTION
] = $this->callback
;
733 $this->curlOptions
[CURLOPT_HEADERFUNCTION
] = array( $this, "readHeader" );
734 $this->curlOptions
[CURLOPT_MAXREDIRS
] = $this->maxRedirects
;
735 $this->curlOptions
[CURLOPT_ENCODING
] = ""; # Enable compression
737 /* not sure these two are actually necessary */
738 if ( isset( $this->reqHeaders
['Referer'] ) ) {
739 $this->curlOptions
[CURLOPT_REFERER
] = $this->reqHeaders
['Referer'];
741 $this->curlOptions
[CURLOPT_USERAGENT
] = $this->reqHeaders
['User-Agent'];
743 $this->curlOptions
[CURLOPT_SSL_VERIFYHOST
] = $this->sslVerifyHost ?
2 : 0;
744 $this->curlOptions
[CURLOPT_SSL_VERIFYPEER
] = $this->sslVerifyCert
;
746 if ( $this->caInfo
) {
747 $this->curlOptions
[CURLOPT_CAINFO
] = $this->caInfo
;
750 if ( $this->headersOnly
) {
751 $this->curlOptions
[CURLOPT_NOBODY
] = true;
752 $this->curlOptions
[CURLOPT_HEADER
] = true;
753 } elseif ( $this->method
== 'POST' ) {
754 $this->curlOptions
[CURLOPT_POST
] = true;
755 $this->curlOptions
[CURLOPT_POSTFIELDS
] = $this->postData
;
756 // Suppress 'Expect: 100-continue' header, as some servers
757 // will reject it with a 417 and Curl won't auto retry
758 // with HTTP 1.0 fallback
759 $this->reqHeaders
['Expect'] = '';
761 $this->curlOptions
[CURLOPT_CUSTOMREQUEST
] = $this->method
;
764 $this->curlOptions
[CURLOPT_HTTPHEADER
] = $this->getHeaderList();
766 $curlHandle = curl_init( $this->url
);
768 if ( !curl_setopt_array( $curlHandle, $this->curlOptions
) ) {
769 wfProfileOut( __METHOD__
);
770 throw new MWException( "Error setting curl options." );
773 if ( $this->followRedirects
&& $this->canFollowRedirects() ) {
774 wfSuppressWarnings();
775 if ( ! curl_setopt( $curlHandle, CURLOPT_FOLLOWLOCATION
, true ) ) {
776 wfDebug( __METHOD__
. ": Couldn't set CURLOPT_FOLLOWLOCATION. " .
777 "Probably safe_mode or open_basedir is set.\n" );
778 // Continue the processing. If it were in curl_setopt_array,
779 // processing would have halted on its entry
784 if ( false === curl_exec( $curlHandle ) ) {
785 $code = curl_error( $curlHandle );
787 if ( isset( self
::$curlMessageMap[$code] ) ) {
788 $this->status
->fatal( self
::$curlMessageMap[$code] );
790 $this->status
->fatal( 'http-curl-error', curl_error( $curlHandle ) );
793 $this->headerList
= explode( "\r\n", $this->headerText
);
796 curl_close( $curlHandle );
798 $this->parseHeader();
801 wfProfileOut( __METHOD__
);
803 return $this->status
;
809 public function canFollowRedirects() {
810 if ( strval( ini_get( 'open_basedir' ) ) !== '' ||
wfIniGetBool( 'safe_mode' ) ) {
811 wfDebug( "Cannot follow redirects in safe mode\n" );
815 if ( !defined( 'CURLOPT_REDIR_PROTOCOLS' ) ) {
816 wfDebug( "Cannot follow redirects with libcurl < 7.19.4 due to CVE-2009-0037\n" );
824 class PhpHttpRequest
extends MWHttpRequest
{
830 protected function urlToTcp( $url ) {
831 $parsedUrl = parse_url( $url );
833 return 'tcp://' . $parsedUrl['host'] . ':' . $parsedUrl['port'];
836 public function execute() {
837 wfProfileIn( __METHOD__
);
841 if ( is_array( $this->postData
) ) {
842 $this->postData
= wfArrayToCgi( $this->postData
);
845 if ( $this->parsedUrl
['scheme'] != 'http' &&
846 $this->parsedUrl
['scheme'] != 'https' ) {
847 $this->status
->fatal( 'http-invalid-scheme', $this->parsedUrl
['scheme'] );
850 $this->reqHeaders
['Accept'] = "*/*";
851 if ( $this->method
== 'POST' ) {
852 // Required for HTTP 1.0 POSTs
853 $this->reqHeaders
['Content-Length'] = strlen( $this->postData
);
854 if( !isset( $this->reqHeaders
['Content-Type'] ) ) {
855 $this->reqHeaders
['Content-Type'] = "application/x-www-form-urlencoded";
860 if ( $this->proxy
) {
861 $options['proxy'] = $this->urlToTCP( $this->proxy
);
862 $options['request_fulluri'] = true;
865 if ( !$this->followRedirects
) {
866 $options['max_redirects'] = 0;
868 $options['max_redirects'] = $this->maxRedirects
;
871 $options['method'] = $this->method
;
872 $options['header'] = implode( "\r\n", $this->getHeaderList() );
873 // Note that at some future point we may want to support
874 // HTTP/1.1, but we'd have to write support for chunking
875 // in version of PHP < 5.3.1
876 $options['protocol_version'] = "1.0";
878 // This is how we tell PHP we want to deal with 404s (for example) ourselves.
879 // Only works on 5.2.10+
880 $options['ignore_errors'] = true;
882 if ( $this->postData
) {
883 $options['content'] = $this->postData
;
886 $options['timeout'] = $this->timeout
;
888 $context = stream_context_create( array( 'http' => $options ) );
890 $this->headerList
= array();
898 wfSuppressWarnings();
899 $fh = fopen( $url, "r", false, $context );
906 $result = stream_get_meta_data( $fh );
907 $this->headerList
= $result['wrapper_data'];
908 $this->parseHeader();
910 if ( !$this->followRedirects
) {
914 # Handle manual redirection
915 if ( !$this->isRedirect() ||
$reqCount > $this->maxRedirects
) {
918 # Check security of URL
919 $url = $this->getResponseHeader( "Location" );
921 if ( !Http
::isValidURI( $url ) ) {
922 wfDebug( __METHOD__
. ": insecure redirection\n" );
929 if ( $fh === false ) {
930 $this->status
->fatal( 'http-request-error' );
931 wfProfileOut( __METHOD__
);
932 return $this->status
;
935 if ( $result['timed_out'] ) {
936 $this->status
->fatal( 'http-timed-out', $this->url
);
937 wfProfileOut( __METHOD__
);
938 return $this->status
;
941 // If everything went OK, or we received some error code
942 // get the response body content.
943 if ( $this->status
->isOK()
944 ||
(int)$this->respStatus
>= 300) {
945 while ( !feof( $fh ) ) {
946 $buf = fread( $fh, 8192 );
948 if ( $buf === false ) {
949 $this->status
->fatal( 'http-read-error' );
953 if ( strlen( $buf ) ) {
954 call_user_func( $this->callback
, $fh, $buf );
960 wfProfileOut( __METHOD__
);
962 return $this->status
;