]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_httapi] Introduction of connect-timeout param
authorSaurabh <saurabhkumar.iitrke@gmail.com>
Wed, 26 Feb 2020 19:08:21 +0000 (00:38 +0530)
committerGitHub <noreply@github.com>
Wed, 26 Feb 2020 19:08:21 +0000 (23:08 +0400)
conf/vanilla/autoload_configs/httapi.conf.xml
src/mod/applications/mod_httapi/conf/autoload_configs/httapi.conf.xml
src/mod/applications/mod_httapi/docs/mod_httapi_doc.txt
src/mod/applications/mod_httapi/mod_httapi.c

index e19210b4da58e11e508f10ce18d6f6fd501fd518..c3566d148a14189920819694ecf93ccf5d44a78b 100644 (file)
        <!-- <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.
index e6435667034222518c1b9a9ef715ee221b296822..1aa4377c58017e8c6b445dc0c5428f5d3d6e45d5 100644 (file)
        <!-- <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.
index b313dc5e15a0b94e10b9e9535a0419cb63322ea6..1fdb3b4d39feee0e3d885dfb29354ffabac2eb0d 100644 (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.
index b0e4e4803c75f80399a82d92f21497d5e107184c..7413a39e4a05d718870699f95827dcb20819d021 100644 (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);
        }