summaryrefslogtreecommitdiff
path: root/includes/HttpFunctions.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/HttpFunctions.php')
-rw-r--r--includes/HttpFunctions.php46
1 files changed, 25 insertions, 21 deletions
diff --git a/includes/HttpFunctions.php b/includes/HttpFunctions.php
index 8e48da46..dc65c67e 100644
--- a/includes/HttpFunctions.php
+++ b/includes/HttpFunctions.php
@@ -35,9 +35,9 @@ class Http {
/**
* Perform an HTTP request
*
- * @param $method String: HTTP method. Usually GET/POST
- * @param $url String: full URL to act on. If protocol-relative, will be expanded to an http:// URL
- * @param $options Array: options to pass to MWHttpRequest object.
+ * @param string $method HTTP method. Usually GET/POST
+ * @param string $url full URL to act on. If protocol-relative, will be expanded to an http:// URL
+ * @param array $options options to pass to MWHttpRequest object.
* Possible keys for the array:
* - timeout Timeout length in seconds
* - postData An array of key-value pairs or a url-encoded form data
@@ -103,7 +103,7 @@ class Http {
/**
* Check if the URL can be served by localhost
*
- * @param $url String: full url to check
+ * @param string $url full url to check
* @return Boolean
*/
public static function isLocalURL( $url ) {
@@ -209,8 +209,8 @@ class MWHttpRequest {
public $status;
/**
- * @param $url String: url to use. If protocol-relative, will be expanded to an http:// URL
- * @param $options Array: (optional) extra params to pass (see Http::request())
+ * @param string $url url to use. If protocol-relative, will be expanded to an http:// URL
+ * @param array $options (optional) extra params to pass (see Http::request())
*/
protected function __construct( $url, $options = array() ) {
global $wgHTTPTimeout;
@@ -234,7 +234,7 @@ class MWHttpRequest {
}
$members = array( "postData", "proxy", "noProxy", "sslVerifyHost", "caInfo",
- "method", "followRedirects", "maxRedirects", "sslVerifyCert", "callback" );
+ "method", "followRedirects", "maxRedirects", "sslVerifyCert", "callback" );
foreach ( $members as $o ) {
if ( isset( $options[$o] ) ) {
@@ -263,8 +263,9 @@ class MWHttpRequest {
/**
* Generate a new request object
- * @param $url String: url to use
- * @param $options Array: (optional) extra params to pass (see Http::request())
+ * @param string $url url to use
+ * @param array $options (optional) extra params to pass (see Http::request())
+ * @throws MWException
* @return CurlHttpRequest|PhpHttpRequest
* @see MWHttpRequest::__construct
*/
@@ -273,7 +274,7 @@ class MWHttpRequest {
Http::$httpEngine = function_exists( 'curl_init' ) ? 'curl' : 'php';
} elseif ( Http::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) {
throw new MWException( __METHOD__ . ': curl (http://php.net/curl) is not installed, but' .
- ' Http::$httpEngine is set to "curl"' );
+ ' Http::$httpEngine is set to "curl"' );
}
switch( Http::$httpEngine ) {
@@ -317,21 +318,24 @@ class MWHttpRequest {
public function proxySetup() {
global $wgHTTPProxy;
- if ( $this->proxy || !$this->noProxy ) {
+ // If there is an explicit proxy set and proxies are not disabled, then use it
+ if ( $this->proxy && !$this->noProxy ) {
return;
}
+ // Otherwise, fallback to $wgHTTPProxy/http_proxy (when set) if this is not a machine
+ // local URL and proxies are not disabled
if ( Http::isLocalURL( $this->url ) || $this->noProxy ) {
$this->proxy = '';
} elseif ( $wgHTTPProxy ) {
- $this->proxy = $wgHTTPProxy ;
+ $this->proxy = $wgHTTPProxy;
} elseif ( getenv( "http_proxy" ) ) {
$this->proxy = getenv( "http_proxy" );
}
}
/**
- * Set the refererer header
+ * Set the referrer header
*/
public function setReferer( $url ) {
$this->setHeader( 'Referer', $url );
@@ -393,6 +397,7 @@ class MWHttpRequest {
* will be aborted.
*
* @param $callback Callback
+ * @throws MWException
*/
public function setCallback( $callback ) {
if ( !is_callable( $callback ) ) {
@@ -445,7 +450,7 @@ class MWHttpRequest {
/**
* Parses the headers, including the HTTP status code and any
- * Set-Cookie headers. This function expectes the headers to be
+ * Set-Cookie headers. This function expects the headers to be
* found in an array in the member variable headerList.
*/
protected function parseHeader() {
@@ -501,7 +506,6 @@ class MWHttpRequest {
return (int)$this->respStatus;
}
-
/**
* Returns true if the last status code was a redirect.
*
@@ -579,8 +583,8 @@ class MWHttpRequest {
}
/**
- * Sets a cookie. Used before a request to set up any individual
- * cookies. Used internally after a request to parse the
+ * Sets a cookie. Used before a request to set up any individual
+ * cookies. Used internally after a request to parse the
* Set-Cookie headers.
* @see Cookie::set
* @param $name
@@ -631,14 +635,14 @@ class MWHttpRequest {
$locations = $headers[ 'location' ];
$domain = '';
$foundRelativeURI = false;
- $countLocations = count($locations);
+ $countLocations = count( $locations );
for ( $i = $countLocations - 1; $i >= 0; $i-- ) {
$url = parse_url( $locations[ $i ] );
- if ( isset($url[ 'host' ]) ) {
+ if ( isset( $url['host'] ) ) {
$domain = $url[ 'scheme' ] . '://' . $url[ 'host' ];
- break; //found correct URI (with host)
+ break; //found correct URI (with host)
} else {
$foundRelativeURI = true;
}
@@ -810,7 +814,7 @@ class PhpHttpRequest extends MWHttpRequest {
parent::execute();
if ( is_array( $this->postData ) ) {
- $this->postData = wfArrayToCGI( $this->postData );
+ $this->postData = wfArrayToCgi( $this->postData );
}
if ( $this->parsedUrl['scheme'] != 'http' &&