Allow setting of connection timeouts for HTTP requests using cURL
Bug: 47027 Change-Id: I6e64a8bfc58e899149463d305eac672c1e8ad2ba
This commit is contained in:
parent
5e48bc1cc7
commit
58f71c7e9e
2 changed files with 16 additions and 0 deletions
|
|
@ -6167,6 +6167,12 @@ $wgAsyncHTTPTimeout = 25;
|
|||
*/
|
||||
$wgHTTPProxy = false;
|
||||
|
||||
/**
|
||||
* Timeout for connections done internally (in seconds)
|
||||
* Only works for curl
|
||||
*/
|
||||
$wgHTTPConnectTimeout = 5e0;
|
||||
|
||||
/** @} */ # End HTTP client }
|
||||
|
||||
/************************************************************************//**
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ class Http {
|
|||
* @param array $options options to pass to MWHttpRequest object.
|
||||
* Possible keys for the array:
|
||||
* - timeout Timeout length in seconds
|
||||
* - connectTimeout Timeout for connection, in seconds (curl only)
|
||||
* - postData An array of key-value pairs or a url-encoded form data
|
||||
* - proxy The proxy to use.
|
||||
* Otherwise it will use $wgHTTPProxy (if set)
|
||||
|
|
@ -65,6 +66,9 @@ class Http {
|
|||
if ( !isset( $options['timeout'] ) ) {
|
||||
$options['timeout'] = 'default';
|
||||
}
|
||||
if( !isset( $options['connectTimeout'] ) ) {
|
||||
$options['connectTimeout'] = 'default';
|
||||
}
|
||||
|
||||
$req = MWHttpRequest::factory( $url, $options );
|
||||
$status = $req->execute();
|
||||
|
|
@ -232,6 +236,11 @@ class MWHttpRequest {
|
|||
} else {
|
||||
$this->timeout = $wgHTTPTimeout;
|
||||
}
|
||||
if ( isset( $options['connectTimeout'] ) && $options['connectTimeout'] != 'default' ) {
|
||||
$this->connectTimeout = $options['connectTimeout'];
|
||||
} else {
|
||||
$this->connectTimeout = $wgHTTPConnectTimeout;
|
||||
}
|
||||
if ( isset( $options['userAgent'] ) ) {
|
||||
$this->setUserAgent( $options['userAgent'] );
|
||||
}
|
||||
|
|
@ -721,6 +730,7 @@ class CurlHttpRequest extends MWHttpRequest {
|
|||
|
||||
$this->curlOptions[CURLOPT_PROXY] = $this->proxy;
|
||||
$this->curlOptions[CURLOPT_TIMEOUT] = $this->timeout;
|
||||
$this->curlOptions[CURLOPT_CONNECTTIMEOUT_MS] = $this->connectTimeout * 1000;
|
||||
$this->curlOptions[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_0;
|
||||
$this->curlOptions[CURLOPT_WRITEFUNCTION] = $this->callback;
|
||||
$this->curlOptions[CURLOPT_HEADERFUNCTION] = array( $this, "readHeader" );
|
||||
|
|
|
|||
Loading…
Reference in a new issue