[mod_httapi] Introduction of connect-timeout param

This commit is contained in:
Saurabh 2020-02-27 00:38:21 +05:30 committed by GitHub
parent 6decc21669
commit 26b95eea75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 0 deletions

View File

@ -105,6 +105,8 @@
<!-- <param name="ssl-key-password" value="MyPrivateKeyPassword"/> -->
<!-- optional timeout -->
<!-- <param name="timeout" value="10"/> -->
<!-- optional: maximum amount of time in seconds that is allowed to make the connection to the server -->
<!-- <param name="connect-timeout" value="2"/> -->
<!-- optional: use a custom CA certificate in PEM format to verify the peer
with. This is useful if you are acting as your own certificate authority.

View File

@ -105,6 +105,8 @@
<!-- <param name="ssl-key-password" value="MyPrivateKeyPassword"/> -->
<!-- optional timeout -->
<!-- <param name="timeout" value="10"/> -->
<!-- optional: maximum amount of time in seconds that is allowed to make the connection to the server -->
<!-- <param name="connect-timeout" value="2"/> -->
<!-- optional: use a custom CA certificate in PEM format to verify the peer
with. This is useful if you are acting as your own certificate authority.

View File

@ -319,6 +319,8 @@ auth-scheme : <string > basic
disable-100-continue : <true|false> true Disable the 100 continue feature.
method : <string> "" METHOD name to send.
timeout : <number> 0 Timeout waiting for response.
connect-timeout : <number> 0 Timeout to create connection. Use default value 0 to switch to the
default built-in connection timeout - 300 seconds.
enable-cacert-check : <true|false> false Check CA/CERT.
ssl-cert-path : <string> "" path to file.
ssl-key-path : <string> "" path to file.

View File

@ -89,6 +89,7 @@ typedef struct client_profile_s {
switch_hash_t *vars_map;
long auth_scheme;
int timeout;
int connect_timeout;
profile_perms_t perms;
char *ua;
@ -1610,6 +1611,10 @@ static switch_status_t httapi_sync(client_t *client)
switch_curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, client->profile->timeout);
}
if (client->profile->connect_timeout) {
switch_curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, client->profile->connect_timeout);
}
if (client->profile->ssl_cert_file) {
switch_curl_easy_setopt(curl_handle, CURLOPT_SSLCERT, client->profile->ssl_cert_file);
}
@ -1759,6 +1764,7 @@ static switch_status_t do_config(void)
char *method = NULL;
int disable100continue = 1;
int timeout = 0;
int connect_timeout = 0;
uint32_t enable_cacert_check = 0;
char *ssl_cert_file = NULL;
char *ssl_key_file = NULL;
@ -1824,6 +1830,13 @@ static switch_status_t do_config(void)
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't set a negative timeout!\n");
}
} else if (!strcasecmp(var, "connect-timeout")) {
int tmp = atoi(val);
if (tmp >= 0) {
connect_timeout = tmp;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't set a negative connect-timeout!\n");
}
} else if (!strcasecmp(var, "enable-cacert-check") && switch_true(val)) {
enable_cacert_check = 1;
} else if (!strcasecmp(var, "ssl-cert-path")) {
@ -2091,6 +2104,7 @@ static switch_status_t do_config(void)
profile->auth_scheme = auth_scheme;
profile->timeout = timeout;
profile->connect_timeout = connect_timeout;
profile->url = switch_core_strdup(globals.pool, url);
switch_assert(profile->url);
@ -2544,6 +2558,10 @@ static switch_status_t fetch_cache_data(http_file_context_t *context, const char
switch_curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, client->profile->timeout);
}
if (client->profile->connect_timeout) {
switch_curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, client->profile->connect_timeout);
}
if (client->profile->ssl_cert_file) {
switch_curl_easy_setopt(curl_handle, CURLOPT_SSLCERT, client->profile->ssl_cert_file);
}