forked from loafle/openapi-generator-original
Adding Curl connect timeout configuration to PHP generation templates (#4500)
This commit is contained in:
parent
aa1dc0fdd2
commit
43ab14b200
@ -153,6 +153,11 @@ class ApiClient
|
||||
if ($this->config->getCurlTimeout() !== 0) {
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout());
|
||||
}
|
||||
// set connect timeout, if needed
|
||||
if ($this->config->getCurlConnectTimeout() != 0) {
|
||||
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $this->config->getCurlConnectTimeout());
|
||||
}
|
||||
|
||||
// return the result on success, rather than just true
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
|
@ -87,6 +87,13 @@ class Configuration
|
||||
*/
|
||||
protected $curlTimeout = 0;
|
||||
|
||||
/**
|
||||
* Timeout (second) of the HTTP connection, by default set to 0, no timeout
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $curlConnectTimeout = 0;
|
||||
|
||||
/**
|
||||
* User agent of the HTTP request, set to "PHP-Swagger" by default
|
||||
*
|
||||
@ -370,6 +377,33 @@ class Configuration
|
||||
return $this->curlTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTP connect timeout value
|
||||
*
|
||||
* @param integer $seconds Number of seconds before connection times out [set to 0 for no timeout]
|
||||
*
|
||||
* @return Configuration
|
||||
*/
|
||||
public function setCurlConnectTimeout($seconds)
|
||||
{
|
||||
if (!is_numeric($seconds) || $seconds < 0) {
|
||||
throw new \InvalidArgumentException('Connect timeout value must be numeric and a non-negative number.');
|
||||
}
|
||||
|
||||
$this->curlConnectTimeout = $seconds;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the HTTP connect timeout value
|
||||
*
|
||||
* @return string HTTP connect timeout value
|
||||
*/
|
||||
public function getCurlConnectTimeout()
|
||||
{
|
||||
return $this->curlConnectTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets debug flag
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user