/**
* 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
* Otherwise it will use $wgHTTPProxy (if set)
* Otherwise it will use the environment variable "http_proxy" (if set)
* - noProxy Don't use any proxy at all. Takes precedence over proxy value(s).
- * - sslVerifyHost (curl only) Set to 2 to verify hostname against certificate
- * Setting to 1 (or true) will NOT verify the host name. It will
- * only check its existence. Setting to 0 (or false) disables entirely.
+ * - sslVerifyHost (curl only) Verify hostname against certificate
* - sslVerifyCert (curl only) Verify SSL certificate
* - caInfo (curl only) Provide CA information
* - maxRedirects Maximum number of redirects to follow (defaults to 5)
/**
* 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 ) {
protected $postData = null;
protected $proxy = null;
protected $noProxy = false;
- /**
- * Parameter passed to Curl that specifies whether
- * to validate SSL certificates.
- *
- * Setting to 0 disables entirely. Setting to 1 checks
- * the existence of a CN, but doesn't verify it. Setting
- * to 2 (the default) actually verifies the host.
- */
- protected $sslVerifyHost = 2;
+ protected $sslVerifyHost = true;
protected $sslVerifyCert = true;
protected $caInfo = null;
protected $method = "GET";
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;
}
$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] ) ) {
/**
* 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
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 ) {
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" );
}
return (int)$this->respStatus;
}
-
/**
* Returns true if the last status code was a redirect.
*
$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;
}
}
$this->curlOptions[CURLOPT_USERAGENT] = $this->reqHeaders['User-Agent'];
- if ( isset( $this->sslVerifyHost ) ) {
- $this->curlOptions[CURLOPT_SSL_VERIFYHOST] = $this->sslVerifyHost;
- }
-
- if ( isset( $this->sslVerifyCert ) ) {
- $this->curlOptions[CURLOPT_SSL_VERIFYPEER] = $this->sslVerifyCert;
- }
+ $this->curlOptions[CURLOPT_SSL_VERIFYHOST] = $this->sslVerifyHost ? 2 : 0;
+ $this->curlOptions[CURLOPT_SSL_VERIFYPEER] = $this->sslVerifyCert;
if ( $this->caInfo ) {
$this->curlOptions[CURLOPT_CAINFO] = $this->caInfo;