7 * Various HTTP related functions
11 static $httpEngine = false;
14 * Perform an HTTP request
16 * @param $method String: HTTP method. Usually GET/POST
17 * @param $url String: full URL to act on
18 * @param $options Array: options to pass to HttpRequest object.
19 * Possible keys for the array:
20 * - timeout Timeout length in seconds
21 * - postData An array of key-value pairs or a url-encoded form data
22 * - proxy The proxy to use.
23 * Will use $wgHTTPProxy (if set) otherwise.
24 * - noProxy Override $wgHTTPProxy (if set) and don't use any proxy at all.
25 * - sslVerifyHost (curl only) Verify hostname against certificate
26 * - sslVerifyCert (curl only) Verify SSL certificate
27 * - caInfo (curl only) Provide CA information
28 * - maxRedirects Maximum number of redirects to follow (defaults to 5)
29 * - followRedirects Whether to follow redirects (defaults to false).
30 * Note: this should only be used when the target URL is trusted,
31 * to avoid attacks on intranet services accessible by HTTP.
32 * @return Mixed: (bool)false on failure or a string on success
34 public static function request( $method, $url, $options = array() ) {
35 $url = wfExpandUrl( $url );
36 wfDebug( "HTTP: $method: $url\n" );
37 $options['method'] = strtoupper( $method );
38 if ( !isset( $options['timeout'] ) ) {
39 $options['timeout'] = 'default';
41 $req = HttpRequest
::factory( $url, $options );
42 $status = $req->execute();
43 if ( $status->isOK() ) {
44 return $req->getContent();
51 * Simple wrapper for Http::request( 'GET' )
52 * @see Http::request()
54 public static function get( $url, $timeout = 'default', $options = array() ) {
55 $options['timeout'] = $timeout;
56 return Http
::request( 'GET', $url, $options );
60 * Simple wrapper for Http::request( 'POST' )
61 * @see Http::request()
63 public static function post( $url, $options = array() ) {
64 return Http
::request( 'POST', $url, $options );
68 * Check if the URL can be served by localhost
70 * @param $url String: full url to check
73 public static function isLocalURL( $url ) {
74 global $wgCommandLineMode, $wgConf;
75 if ( $wgCommandLineMode ) {
81 if ( preg_match( '!^http://([\w.-]+)[/:].*$!', $url, $matches ) ) {
84 $domainParts = explode( '.', $host );
85 // Check if this domain or any superdomain is listed in $wgConf as a local virtual host
86 $domainParts = array_reverse( $domainParts );
87 for ( $i = 0; $i < count( $domainParts ); $i++
) {
88 $domainPart = $domainParts[$i];
90 $domain = $domainPart;
92 $domain = $domainPart . '.' . $domain;
94 if ( $wgConf->isLocalVHost( $domain ) ) {
103 * A standard user-agent we can use for external requests.
106 public static function userAgent() {
108 return "MediaWiki/$wgVersion";
112 * Checks that the given URI is a valid one
114 * @param $uri Mixed: URI to check for validity
117 public static function isValidURI( $uri ) {
119 '/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/',
127 * This wrapper class will call out to curl (if available) or fallback
128 * to regular PHP if necessary for handling internal HTTP requests.
132 protected $timeout = 'default';
133 protected $headersOnly = null;
134 protected $postData = null;
135 protected $proxy = null;
136 protected $noProxy = false;
137 protected $sslVerifyHost = true;
138 protected $sslVerifyCert = true;
139 protected $caInfo = null;
140 protected $method = "GET";
141 protected $reqHeaders = array();
143 protected $parsedUrl;
145 protected $maxRedirects = 5;
146 protected $followRedirects = false;
148 protected $cookieJar;
150 protected $headerList = array();
151 protected $respVersion = "0.9";
152 protected $respStatus = "200 Ok";
153 protected $respHeaders = array();
158 * @param $url String: url to use
159 * @param $options Array: (optional) extra params to pass (see Http::request())
161 function __construct( $url, $options = array() ) {
162 global $wgHTTPTimeout;
165 $this->parsedUrl
= parse_url( $url );
167 if ( !Http
::isValidURI( $this->url
) ) {
168 $this->status
= Status
::newFatal('http-invalid-url');
170 $this->status
= Status
::newGood( 100 ); // continue
173 if ( isset($options['timeout']) && $options['timeout'] != 'default' ) {
174 $this->timeout
= $options['timeout'];
176 $this->timeout
= $wgHTTPTimeout;
179 $members = array( "postData", "proxy", "noProxy", "sslVerifyHost", "caInfo",
180 "method", "followRedirects", "maxRedirects", "sslVerifyCert" );
181 foreach ( $members as $o ) {
182 if ( isset($options[$o]) ) {
183 $this->$o = $options[$o];
189 * Generate a new request object
190 * @see HttpRequest::__construct
192 public static function factory( $url, $options = null ) {
193 if ( !Http
::$httpEngine ) {
194 Http
::$httpEngine = function_exists( 'curl_init' ) ?
'curl' : 'php';
195 } elseif ( Http
::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) {
196 throw new MWException( __METHOD__
.': curl (http://php.net/curl) is not installed, but'.
197 ' Http::$httpEngine is set to "curl"' );
200 switch( Http
::$httpEngine ) {
202 return new CurlHttpRequest( $url, $options );
204 if ( !wfIniGetBool( 'allow_url_fopen' ) ) {
205 throw new MWException( __METHOD__
.': allow_url_fopen needs to be enabled for pure PHP'.
206 ' http requests to work. If possible, curl should be used instead. See http://php.net/curl.' );
208 return new PhpHttpRequest( $url, $options );
210 throw new MWException( __METHOD__
.': The setting of Http::$httpEngine is not valid.' );
215 * Get the body, or content, of the response to the request
219 public function getContent() {
220 return $this->content
;
224 * Set the parameters of the request
227 * @todo overload the args param
229 public function setData($args) {
230 $this->postData
= $args;
234 * Take care of setting up the proxy
235 * (override in subclass)
239 public function proxySetup() {
242 if ( $this->proxy
) {
245 if ( Http
::isLocalURL( $this->url
) ) {
246 $this->proxy
= 'http://localhost:80/';
247 } elseif ( $wgHTTPProxy ) {
248 $this->proxy
= $wgHTTPProxy ;
249 } elseif ( getenv( "http_proxy" ) ) {
250 $this->proxy
= getenv( "http_proxy" );
255 * Set the refererer header
257 public function setReferer( $url ) {
258 $this->setHeader('Referer', $url);
264 public function setUserAgent( $UA ) {
265 $this->setHeader('User-Agent', $UA);
269 * Set an arbitrary header
271 public function setHeader($name, $value) {
272 // I feel like I should normalize the case here...
273 $this->reqHeaders
[$name] = $value;
277 * Get an array of the headers
279 public function getHeaderList() {
282 if( $this->cookieJar
) {
283 $this->reqHeaders
['Cookie'] =
284 $this->cookieJar
->serializeToHttpRequest($this->parsedUrl
['path'],
285 $this->parsedUrl
['host']);
287 foreach($this->reqHeaders
as $name => $value) {
288 $list[] = "$name: $value";
296 * @param $callback Callback
298 public function setCallback( $callback ) {
299 $this->callback
= $callback;
303 * A generic callback to read the body of the response from a remote
307 * @param $content String
309 public function read( $fh, $content ) {
310 $this->content
.= $content;
311 return strlen( $content );
315 * Take care of whatever is necessary to perform the URI request.
319 public function execute() {
324 if( strtoupper($this->method
) == "HEAD" ) {
325 $this->headersOnly
= true;
328 if ( is_array( $this->postData
) ) {
329 $this->postData
= wfArrayToCGI( $this->postData
);
332 if ( is_object( $wgTitle ) && !isset($this->reqHeaders
['Referer']) ) {
333 $this->setReferer( $wgTitle->getFullURL() );
336 if ( !$this->noProxy
) {
340 if ( !$this->callback
) {
341 $this->setCallback( array( $this, 'read' ) );
344 if ( !isset($this->reqHeaders
['User-Agent']) ) {
345 $this->setUserAgent(Http
::userAgent());
350 * Parses the headers, including the HTTP status code and any
351 * Set-Cookie headers. This function expectes the headers to be
352 * found in an array in the member variable headerList.
356 protected function parseHeader() {
358 foreach( $this->headerList
as $header ) {
359 if( preg_match( "#^HTTP/([0-9.]+) (.*)#", $header, $match ) ) {
360 $this->respVersion
= $match[1];
361 $this->respStatus
= $match[2];
362 } elseif( preg_match( "#^[ \t]#", $header ) ) {
363 $last = count($this->respHeaders
[$lastname]) - 1;
364 $this->respHeaders
[$lastname][$last] .= "\r\n$header";
365 } elseif( preg_match( "#^([^:]*):[\t ]*(.*)#", $header, $match ) ) {
366 $this->respHeaders
[strtolower( $match[1] )][] = $match[2];
367 $lastname = strtolower( $match[1] );
371 $this->parseCookies();
375 * Sets the member variable status to a fatal status if the HTTP
376 * status code was not 200.
380 protected function setStatus() {
381 if( !$this->respHeaders
) {
382 $this->parseHeader();
385 if((int)$this->respStatus
!== 200) {
386 list( $code, $message ) = explode(" ", $this->respStatus
, 2);
387 $this->status
->fatal("http-bad-status", $code, $message );
393 * Returns true if the last status code was a redirect.
397 public function isRedirect() {
398 if( !$this->respHeaders
) {
399 $this->parseHeader();
402 $status = (int)$this->respStatus
;
403 if ( $status >= 300 && $status <= 303 ) {
410 * Returns an associative array of response headers after the
411 * request has been executed. Because some headers
412 * (e.g. Set-Cookie) can appear more than once the, each value of
413 * the associative array is an array of the values given.
417 public function getResponseHeaders() {
418 if( !$this->respHeaders
) {
419 $this->parseHeader();
421 return $this->respHeaders
;
425 * Returns the value of the given response header.
427 * @param $header String
430 public function getResponseHeader($header) {
431 if( !$this->respHeaders
) {
432 $this->parseHeader();
434 if ( isset( $this->respHeaders
[strtolower ( $header ) ] ) ) {
435 $v = $this->respHeaders
[strtolower ( $header ) ];
436 return $v[count( $v ) - 1];
442 * Tells the HttpRequest object to use this pre-loaded CookieJar.
444 * @param $jar CookieJar
446 public function setCookieJar( $jar ) {
447 $this->cookieJar
= $jar;
451 * Returns the cookie jar in use.
455 public function getCookieJar() {
456 if( !$this->respHeaders
) {
457 $this->parseHeader();
459 return $this->cookieJar
;
463 * Sets a cookie. Used before a request to set up any individual
464 * cookies. Used internally after a request to parse the
465 * Set-Cookie headers.
468 public function setCookie( $name, $value = null, $attr = null) {
469 if( !$this->cookieJar
) {
470 $this->cookieJar
= new CookieJar
;
472 $this->cookieJar
->setCookie($name, $value, $attr);
476 * Parse the cookies in the response headers and store them in the cookie jar.
478 protected function parseCookies() {
479 if( !$this->cookieJar
) {
480 $this->cookieJar
= new CookieJar
;
482 if( isset( $this->respHeaders
['set-cookie'] ) ) {
483 $url = parse_url( $this->getFinalUrl() );
484 foreach( $this->respHeaders
['set-cookie'] as $cookie ) {
485 $this->cookieJar
->parseCookieResponseHeader( $cookie, $url['host'] );
491 * Returns the final URL after all redirections.
495 public function getFinalUrl() {
496 $location = $this->getResponseHeader("Location");
505 * Returns true if the backend can follow redirects. Overridden by the
508 public function canFollowRedirects() {
520 protected $isSessionKey = true;
521 // TO IMPLEMENT protected $secure
522 // TO IMPLEMENT? protected $maxAge (add onto expires)
523 // TO IMPLEMENT? protected $version
524 // TO IMPLEMENT? protected $comment
526 function __construct( $name, $value, $attr ) {
528 $this->set( $value, $attr );
532 * Sets a cookie. Used before a request to set up any individual
533 * cookies. Used internally after a request to parse the
534 * Set-Cookie headers.
536 * @param $value String: the value of the cookie
537 * @param $attr Array: possible key/values:
538 * expires A date string
539 * path The path this cookie is used on
540 * domain Domain this cookie is used on
542 public function set( $value, $attr ) {
543 $this->value
= $value;
544 if( isset( $attr['expires'] ) ) {
545 $this->isSessionKey
= false;
546 $this->expires
= strtotime( $attr['expires'] );
548 if( isset( $attr['path'] ) ) {
549 $this->path
= $attr['path'];
553 if( isset( $attr['domain'] ) ) {
554 if( self
::validateCookieDomain( $attr['domain'] ) ) {
555 $this->domain
= $attr['domain'];
558 throw new MWException("You must specify a domain.");
563 * Return the true if the cookie is valid is valid. Otherwise,
564 * false. The uses a method similar to IE cookie security
566 * http://kuza55.blogspot.com/2008/02/understanding-cookie-security.html
567 * A better method might be to use a blacklist like
568 * http://publicsuffix.org/
570 * @param $domain String: the domain to validate
571 * @param $originDomain String: (optional) the domain the cookie originates from
574 public static function validateCookieDomain( $domain, $originDomain = null) {
575 // Don't allow a trailing dot
576 if( substr( $domain, -1 ) == "." ) return false;
578 $dc = explode(".", $domain);
580 // Only allow full, valid IP addresses
581 if( preg_match( '/^[0-9.]+$/', $domain ) ) {
582 if( count( $dc ) != 4 ) return false;
584 if( ip2long( $domain ) === false ) return false;
586 if( $originDomain == null ||
$originDomain == $domain ) return true;
590 // Don't allow cookies for "co.uk" or "gov.uk", etc, but allow "supermarket.uk"
591 if( strrpos( $domain, "." ) - strlen( $domain ) == -3 ) {
592 if( (count($dc) == 2 && strlen( $dc[0] ) <= 2 )
593 ||
(count($dc) == 3 && strlen( $dc[0] ) == "" && strlen( $dc[1] ) <= 2 ) ) {
596 if( (count($dc) == 2 ||
(count($dc) == 3 && $dc[0] == "") )
597 && preg_match( '/(com|net|org|gov|edu)\...$/', $domain) ) {
602 if( $originDomain != null ) {
603 if( substr( $domain, 0, 1 ) != "." && $domain != $originDomain ) {
606 if( substr( $domain, 0, 1 ) == "."
607 && substr_compare( $originDomain, $domain, -strlen( $domain ),
608 strlen( $domain ), TRUE ) != 0 ) {
617 * Serialize the cookie jar into a format useful for HTTP Request headers.
619 * @param $path String: the path that will be used. Required.
620 * @param $domain String: the domain that will be used. Required.
623 public function serializeToHttpRequest( $path, $domain ) {
626 if( $this->canServeDomain( $domain )
627 && $this->canServePath( $path )
628 && $this->isUnExpired() ) {
629 $ret = $this->name
."=". $this->value
;
635 protected function canServeDomain( $domain ) {
636 if( $domain == $this->domain
637 ||
( strlen( $domain) > strlen( $this->domain
)
638 && substr( $this->domain
, 0, 1) == "."
639 && substr_compare( $domain, $this->domain
, -strlen( $this->domain
),
640 strlen( $this->domain
), TRUE ) == 0 ) ) {
646 protected function canServePath( $path ) {
647 if( $this->path
&& substr_compare( $this->path
, $path, 0, strlen( $this->path
) ) == 0 ) {
653 protected function isUnExpired() {
654 if( $this->isSessionKey ||
$this->expires
> time() ) {
663 private $cookie = array();
666 * Set a cookie in the cookie jar. Make sure only one cookie per-name exists.
669 public function setCookie ($name, $value, $attr) {
670 /* cookies: case insensitive, so this should work.
671 * We'll still send the cookies back in the same case we got them, though.
673 $index = strtoupper($name);
674 if( isset( $this->cookie
[$index] ) ) {
675 $this->cookie
[$index]->set( $value, $attr );
677 $this->cookie
[$index] = new Cookie( $name, $value, $attr );
682 * @see Cookie::serializeToHttpRequest
684 public function serializeToHttpRequest( $path, $domain ) {
687 foreach( $this->cookie
as $c ) {
688 $serialized = $c->serializeToHttpRequest( $path, $domain );
689 if ( $serialized ) $cookies[] = $serialized;
692 return implode("; ", $cookies);
696 * Parse the content of an Set-Cookie HTTP Response header.
698 * @param $cookie String
699 * @param $domain String: cookie's domain
701 public function parseCookieResponseHeader ( $cookie, $domain ) {
702 $len = strlen( "Set-Cookie:" );
703 if ( substr_compare( "Set-Cookie:", $cookie, 0, $len, TRUE ) === 0 ) {
704 $cookie = substr( $cookie, $len );
707 $bit = array_map( 'trim', explode( ";", $cookie ) );
708 if ( count($bit) >= 1 ) {
709 list($name, $value) = explode( "=", array_shift( $bit ), 2 );
711 foreach( $bit as $piece ) {
712 $parts = explode( "=", $piece );
713 if( count( $parts ) > 1 ) {
714 $attr[strtolower( $parts[0] )] = $parts[1];
716 $attr[strtolower( $parts[0] )] = true;
720 if( !isset( $attr['domain'] ) ) {
721 $attr['domain'] = $domain;
722 } elseif ( !Cookie
::validateCookieDomain( $attr['domain'], $domain ) ) {
725 $this->setCookie( $name, $value, $attr );
732 * HttpRequest implemented using internal curl compiled into PHP
734 class CurlHttpRequest
extends HttpRequest
{
735 static $curlMessageMap = array(
736 6 => 'http-host-unreachable',
737 28 => 'http-timed-out'
740 protected $curlOptions = array();
741 protected $headerText = "";
743 protected function readHeader( $fh, $content ) {
744 $this->headerText
.= $content;
745 return strlen( $content );
748 public function execute() {
750 if ( !$this->status
->isOK() ) {
751 return $this->status
;
753 $this->curlOptions
[CURLOPT_PROXY
] = $this->proxy
;
754 $this->curlOptions
[CURLOPT_TIMEOUT
] = $this->timeout
;
755 $this->curlOptions
[CURLOPT_HTTP_VERSION
] = CURL_HTTP_VERSION_1_0
;
756 $this->curlOptions
[CURLOPT_WRITEFUNCTION
] = $this->callback
;
757 $this->curlOptions
[CURLOPT_HEADERFUNCTION
] = array($this, "readHeader");
758 $this->curlOptions
[CURLOPT_MAXREDIRS
] = $this->maxRedirects
;
759 $this->curlOptions
[CURLOPT_ENCODING
] = ""; # Enable compression
761 /* not sure these two are actually necessary */
762 if(isset($this->reqHeaders
['Referer'])) {
763 $this->curlOptions
[CURLOPT_REFERER
] = $this->reqHeaders
['Referer'];
765 $this->curlOptions
[CURLOPT_USERAGENT
] = $this->reqHeaders
['User-Agent'];
767 if ( isset( $this->sslVerifyHost
) ) {
768 $this->curlOptions
[CURLOPT_SSL_VERIFYHOST
] = $this->sslVerifyHost
;
771 if ( isset( $this->sslVerifyCert
) ) {
772 $this->curlOptions
[CURLOPT_SSL_VERIFYPEER
] = $this->sslVerifyCert
;
775 if ( $this->caInfo
) {
776 $this->curlOptions
[CURLOPT_CAINFO
] = $this->caInfo
;
779 if ( $this->headersOnly
) {
780 $this->curlOptions
[CURLOPT_NOBODY
] = true;
781 $this->curlOptions
[CURLOPT_HEADER
] = true;
782 } elseif ( $this->method
== 'POST' ) {
783 $this->curlOptions
[CURLOPT_POST
] = true;
784 $this->curlOptions
[CURLOPT_POSTFIELDS
] = $this->postData
;
785 // Suppress 'Expect: 100-continue' header, as some servers
786 // will reject it with a 417 and Curl won't auto retry
787 // with HTTP 1.0 fallback
788 $this->reqHeaders
['Expect'] = '';
790 $this->curlOptions
[CURLOPT_CUSTOMREQUEST
] = $this->method
;
793 $this->curlOptions
[CURLOPT_HTTPHEADER
] = $this->getHeaderList();
795 $curlHandle = curl_init( $this->url
);
796 if ( !curl_setopt_array( $curlHandle, $this->curlOptions
) ) {
797 throw new MWException("Error setting curl options.");
799 if ( $this->followRedirects
&& $this->canFollowRedirects() ) {
800 if ( ! @curl_setopt
( $curlHandle, CURLOPT_FOLLOWLOCATION
, true ) ) {
801 wfDebug( __METHOD__
.": Couldn't set CURLOPT_FOLLOWLOCATION. " .
802 "Probably safe_mode or open_basedir is set.\n");
803 // Continue the processing. If it were in curl_setopt_array,
804 // processing would have halted on its entry
808 if ( false === curl_exec( $curlHandle ) ) {
809 $code = curl_error( $curlHandle );
811 if ( isset( self
::$curlMessageMap[$code] ) ) {
812 $this->status
->fatal( self
::$curlMessageMap[$code] );
814 $this->status
->fatal( 'http-curl-error', curl_error( $curlHandle ) );
817 $this->headerList
= explode("\r\n", $this->headerText
);
820 curl_close( $curlHandle );
822 $this->parseHeader();
824 return $this->status
;
827 public function canFollowRedirects() {
828 if ( strval( ini_get( 'open_basedir' ) ) !== '' ||
wfIniGetBool( 'safe_mode' ) ) {
829 wfDebug( "Cannot follow redirects in safe mode\n" );
832 if ( !defined( 'CURLOPT_REDIR_PROTOCOLS' ) ) {
833 wfDebug( "Cannot follow redirects with libcurl < 7.19.4 due to CVE-2009-0037\n" );
840 class PhpHttpRequest
extends HttpRequest
{
841 protected function urlToTcp( $url ) {
842 $parsedUrl = parse_url( $url );
844 return 'tcp://' . $parsedUrl['host'] . ':' . $parsedUrl['port'];
847 public function execute() {
850 // At least on Centos 4.8 with PHP 5.1.6, using max_redirects to follow redirects
852 $manuallyRedirect = version_compare( phpversion(), '5.1.7', '<' );
854 if ( $this->parsedUrl
['scheme'] != 'http' ) {
855 $this->status
->fatal( 'http-invalid-scheme', $this->parsedUrl
['scheme'] );
858 $this->reqHeaders
['Accept'] = "*/*";
859 if ( $this->method
== 'POST' ) {
860 // Required for HTTP 1.0 POSTs
861 $this->reqHeaders
['Content-Length'] = strlen( $this->postData
);
862 $this->reqHeaders
['Content-type'] = "application/x-www-form-urlencoded";
866 if ( $this->proxy
&& !$this->noProxy
) {
867 $options['proxy'] = $this->urlToTCP( $this->proxy
);
868 $options['request_fulluri'] = true;
871 if ( !$this->followRedirects ||
$manuallyRedirect ) {
872 $options['max_redirects'] = 0;
874 $options['max_redirects'] = $this->maxRedirects
;
877 $options['method'] = $this->method
;
878 $options['header'] = implode("\r\n", $this->getHeaderList());
879 // Note that at some future point we may want to support
880 // HTTP/1.1, but we'd have to write support for chunking
881 // in version of PHP < 5.3.1
882 $options['protocol_version'] = "1.0";
884 // This is how we tell PHP we want to deal with 404s (for example) ourselves.
885 // Only works on 5.2.10+
886 $options['ignore_errors'] = true;
888 if ( $this->postData
) {
889 $options['content'] = $this->postData
;
893 if ( version_compare( '5.2.1', phpversion(), '>' ) ) {
894 $oldTimeout = ini_set('default_socket_timeout', $this->timeout
);
896 $options['timeout'] = $this->timeout
;
899 $context = stream_context_create( array( 'http' => $options ) );
901 $this->headerList
= array();
906 wfSuppressWarnings();
907 $fh = fopen( $url, "r", false, $context );
912 $result = stream_get_meta_data( $fh );
913 $this->headerList
= $result['wrapper_data'];
914 $this->parseHeader();
915 if ( !$manuallyRedirect ||
!$this->followRedirects
) {
919 # Handle manual redirection
920 if ( !$this->isRedirect() ||
$reqCount > $this->maxRedirects
) {
923 # Check security of URL
924 $url = $this->getResponseHeader("Location");
925 if ( substr( $url, 0, 7 ) !== 'http://' ) {
926 wfDebug( __METHOD__
.": insecure redirection\n" );
931 if ( $oldTimeout !== false ) {
932 ini_set('default_socket_timeout', $oldTimeout);
936 if ( $fh === false ) {
937 $this->status
->fatal( 'http-request-error' );
938 return $this->status
;
941 if ( $result['timed_out'] ) {
942 $this->status
->fatal( 'http-timed-out', $this->url
);
943 return $this->status
;
946 if($this->status
->isOK()) {
947 while ( !feof( $fh ) ) {
948 $buf = fread( $fh, 8192 );
949 if ( $buf === false ) {
950 $this->status
->fatal( 'http-read-error' );
953 if ( strlen( $buf ) ) {
954 call_user_func( $this->callback
, $fh, $buf );
960 return $this->status
;