3 * Various HTTP related functions
7 * Get the contents of a file by HTTP
9 * if $timeout is 'default', $wgHTTPTimeout is used
11 function wfGetHTTP( $url, $timeout = 'default' ) {
12 global $wgServer, $wgHTTPTimeout, $wgHTTPProxy;
15 # Use curl if available
16 if ( function_exists( 'curl_init' ) ) {
17 $c = curl_init( $url );
18 if ( wfIsLocalURL( $url ) ) {
19 curl_setopt( $c, CURLOPT_PROXY
, 'localhost:80' );
20 } else if ($wgHTTPProxy)
21 curl_setopt($c, CURLOPT_PROXY
, $wgHTTPProxy);
23 if ( $timeout == 'default' ) {
24 $timeout = $wgHTTPTimeout;
26 curl_setopt( $c, CURLOPT_TIMEOUT
, $timeout );
29 $text = ob_get_contents();
33 # Otherwise use file_get_contents, or its compatibility function from GlobalFunctions.php
34 # This may take 3 minutes to time out, and doesn't have local fetch capabilities
35 $url_fopen = ini_set( 'allow_url_fopen', 1 );
36 $text = file_get_contents( $url );
37 ini_set( 'allow_url_fopen', $url_fopen );
43 * Check if the URL can be served by localhost
45 function wfIsLocalURL( $url ) {
48 if ( preg_match( '!^http://([\w.-]+)[/:].*$!', $url, $matches ) ) {
51 $domainParts = explode( '.', $host );
52 // Check if this domain or any superdomain is listed in $wgConf as a local virtual host
53 $domainParts = array_reverse( $domainParts );
54 for ( $i = 0; $i < count( $domainParts ); $i++
) {
55 $domainPart = $domainParts[$i];
57 $domain = $domainPart;
59 $domain = $domainPart . '.' . $domain;
61 if ( $wgConf->isLocalVHost( $domain ) ) {